List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:com.onesignal.GenerateNotification.java
static void createSummaryNotification(Context inContext, boolean updateSummary, JSONObject gcmBundle) { if (updateSummary) setStatics(inContext);//from w ww.j a va 2 s . c om String group = null; try { group = gcmBundle.getString("grp"); } catch (Throwable t) { } Random random = new Random(); PendingIntent summaryDeleteIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseDeleteIntent(0).putExtra("summary", group)); OneSignalDbHelper dbHelper = new OneSignalDbHelper(currentContext); SQLiteDatabase writableDb = dbHelper.getWritableDatabase(); String[] retColumn = { NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, NotificationTable.COLUMN_NAME_FULL_DATA, NotificationTable.COLUMN_NAME_IS_SUMMARY, NotificationTable.COLUMN_NAME_TITLE, NotificationTable.COLUMN_NAME_MESSAGE }; String[] whereArgs = { group }; Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, retColumn, NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0", whereArgs, null, // group by null, // filter by row groups NotificationTable._ID + " DESC" // sort order, new to old ); Notification summaryNotification; int summaryNotificationId = random.nextInt(); String firstFullData = null; Collection<SpannableString> summeryList = null; if (cursor.moveToFirst()) { SpannableString spannableString; summeryList = new ArrayList<SpannableString>(); do { if (cursor.getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_IS_SUMMARY)) == 1) summaryNotificationId = cursor .getInt(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID)); else { String title = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_TITLE)); if (title == null) title = ""; else title += " "; // Html.fromHtml("<strong>" + line1Title + "</strong> " + gcmBundle.getString("alert")); String msg = cursor.getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_MESSAGE)); spannableString = new SpannableString(title + msg); if (title.length() > 0) spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(), 0); summeryList.add(spannableString); if (firstFullData == null) firstFullData = cursor .getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA)); } } while (cursor.moveToNext()); if (updateSummary) { try { gcmBundle = new JSONObject(firstFullData); } catch (JSONException e) { e.printStackTrace(); } } } if (summeryList != null && (!updateSummary || summeryList.size() > 1)) { int notificationCount = summeryList.size() + (updateSummary ? 0 : 1); String summaryMessage = null; if (gcmBundle.has("grp_msg")) { try { summaryMessage = gcmBundle.getString("grp_msg").replace("$[notif_count]", "" + notificationCount); } catch (Throwable t) { } } if (summaryMessage == null) summaryMessage = notificationCount + " new messages"; JSONObject summaryDataBundle = new JSONObject(); try { summaryDataBundle.put("alert", summaryMessage); } catch (JSONException e) { e.printStackTrace(); } Intent summaryIntent = getNewBaseIntent(summaryNotificationId).putExtra("summary", group) .putExtra("onesignal_data", summaryDataBundle.toString()); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), summaryIntent); NotificationCompat.Builder summeryBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); summeryBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setContentTitle(currentContext.getPackageManager() .getApplicationLabel(currentContext.getApplicationInfo())) .setContentText(summaryMessage).setNumber(notificationCount).setOnlyAlertOnce(updateSummary) .setGroup(group).setGroupSummary(true); if (!updateSummary) summeryBuilder.setTicker(summaryMessage); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String line1Title = null; // Add the latest notification to the summary if (!updateSummary) { try { line1Title = gcmBundle.getString("title"); } catch (Throwable t) { } if (line1Title == null) line1Title = ""; else line1Title += " "; String message = ""; try { message = gcmBundle.getString("alert"); } catch (Throwable t) { } SpannableString spannableString = new SpannableString(line1Title + message); if (line1Title.length() > 0) spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, line1Title.length(), 0); inboxStyle.addLine(spannableString); } for (SpannableString line : summeryList) inboxStyle.addLine(line); inboxStyle.setBigContentTitle(summaryMessage); summeryBuilder.setStyle(inboxStyle); summaryNotification = summeryBuilder.build(); } else { // There currently isn't a visible notification from this group, save the group summary notification id and post it so it looks like a normal notification. ContentValues values = new ContentValues(); values.put(NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID, summaryNotificationId); values.put(NotificationTable.COLUMN_NAME_GROUP_ID, group); values.put(NotificationTable.COLUMN_NAME_IS_SUMMARY, 1); writableDb.insert(NotificationTable.TABLE_NAME, null, values); NotificationCompat.Builder notifBuilder = getBaseNotificationCompatBuilder(gcmBundle, !updateSummary); PendingIntent summaryContentIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseIntent(summaryNotificationId).putExtra("onesignal_data", gcmBundle.toString()) .putExtra("summary", group)); addNotificationActionButtons(gcmBundle, notifBuilder, summaryNotificationId, group); notifBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent) .setOnlyAlertOnce(updateSummary).setGroup(group).setGroupSummary(true); summaryNotification = notifBuilder.build(); } NotificationManagerCompat.from(currentContext).notify(summaryNotificationId, summaryNotification); cursor.close(); writableDb.close(); }
From source file:com.android.emailcommon.provider.Account.java
/** * Clear all account hold flags that are set. * * (This will trigger watchers, and in particular will cause EAS to try and resync the * account(s).)/* w w w. java 2 s .com*/ */ public static void clearSecurityHoldOnAllAccounts(Context context) { ContentResolver resolver = context.getContentResolver(); Cursor c = resolver.query(Account.CONTENT_URI, ACCOUNT_FLAGS_PROJECTION, SECURITY_NONZERO_SELECTION, null, null); try { while (c.moveToNext()) { int flags = c.getInt(ACCOUNT_FLAGS_COLUMN_FLAGS); if (0 != (flags & FLAGS_SECURITY_HOLD)) { ContentValues cv = new ContentValues(); cv.put(AccountColumns.FLAGS, flags & ~FLAGS_SECURITY_HOLD); long accountId = c.getLong(ACCOUNT_FLAGS_COLUMN_ID); Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, accountId); resolver.update(uri, cv, null, null); } } } finally { c.close(); } }
From source file:com.android.contacts.common.model.ContactLoader.java
private static Contact loadEncodedContactEntity(Uri uri, Uri lookupUri) throws JSONException { final String jsonString = uri.getEncodedFragment(); final JSONObject json = new JSONObject(jsonString); final long directoryId = Long.valueOf(uri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY)); final String displayName = json.optString(Contacts.DISPLAY_NAME); final String altDisplayName = json.optString(Contacts.DISPLAY_NAME_ALTERNATIVE, displayName); final int displayNameSource = json.getInt(Contacts.DISPLAY_NAME_SOURCE); final String photoUri = json.optString(Contacts.PHOTO_URI, null); final Contact contact = new Contact(uri, uri, lookupUri, directoryId, null /* lookupKey */, -1 /* id */, -1 /* nameRawContactId */, displayNameSource, 0 /* photoId */, photoUri, displayName, altDisplayName, null /* phoneticName */, false /* starred */, null /* presence */, false /* sendToVoicemail */, null /* customRingtone */, false /* isUserProfile */); contact.setStatuses(new ImmutableMap.Builder<Long, DataStatus>().build()); final String accountName = json.optString(RawContacts.ACCOUNT_NAME, null); final String directoryName = uri.getQueryParameter(Directory.DISPLAY_NAME); if (accountName != null) { final String accountType = json.getString(RawContacts.ACCOUNT_TYPE); contact.setDirectoryMetaData(directoryName, null, accountName, accountType, json.optInt(Directory.EXPORT_SUPPORT, Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY)); } else {/*from www. j ava 2 s .c o m*/ contact.setDirectoryMetaData(directoryName, null, null, null, json.optInt(Directory.EXPORT_SUPPORT, Directory.EXPORT_SUPPORT_ANY_ACCOUNT)); } final ContentValues values = new ContentValues(); values.put(Data._ID, -1); values.put(Data.CONTACT_ID, -1); final RawContact rawContact = new RawContact(values); final JSONObject items = json.getJSONObject(Contacts.CONTENT_ITEM_TYPE); final Iterator keys = items.keys(); while (keys.hasNext()) { final String mimetype = (String) keys.next(); // Could be single object or array. final JSONObject obj = items.optJSONObject(mimetype); if (obj == null) { final JSONArray array = items.getJSONArray(mimetype); for (int i = 0; i < array.length(); i++) { final JSONObject item = array.getJSONObject(i); processOneRecord(rawContact, item, mimetype); } } else { processOneRecord(rawContact, obj, mimetype); } } contact.setRawContacts(new ImmutableList.Builder<RawContact>().add(rawContact).build()); return contact; }
From source file:de.uni_koblenz_landau.apow.helper.SyncHelper.java
/** * Converts a JSONObject to a content value. * @param obj JSONObject/*w w w .j a v a 2s. co m*/ * @return Content value * @throws JSONException */ private static ContentValues JSONToContentValues(JSONObject obj) throws JSONException { ContentValues values = new ContentValues(); Iterator<?> keys = obj.keys(); // Loop through all entries. while (keys.hasNext()) { String key = (String) keys.next(); // Check for data type and insert in the right format. if (!obj.isNull(key) || "".equals(obj.getString(key))) { Object a = obj.get(key); if (a instanceof Integer) { values.put(key, (int) a); } if (a instanceof Double) { values.put(key, (double) a); } if (a instanceof String) { values.put(key, (String) a); } } } return values; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static long insertOfflineSentPost(Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("foo", 1); long ret = dbwrite.insert("offline_sent_posts", null, cv); dbwrite.close();// ww w . j a va 2 s . co m db.close(); return ret; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void subscribeGroup(String group, Context context) { DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbwrite = dbhelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("profile_id", 1); cv.put("name", group); cv.put("lastFetched", -1); cv.put("unread_count", -1); dbwrite.insert("subscribed_groups", null, cv); dbwrite.close();// w ww . ja v a2s. co m dbhelper.close(); }
From source file:android.syncml.pim.PropertyNode.java
public static PropertyNode decode(String encodedString) { PropertyNode propertyNode = new PropertyNode(); String trimed = encodedString.trim(); if (trimed.length() == 0) { return propertyNode; }/* w w w . j a v a 2 s . c o m*/ String[] elems = trimed.split("],"); for (String elem : elems) { int index = elem.indexOf('['); String name = elem.substring(0, index - 1); Pattern pattern = Pattern.compile("(?<!\\\\),"); String[] values = pattern.split(elem.substring(index + 1), -1); if (name.equals("propName")) { propertyNode.propName = values[0]; } else if (name.equals("propGroupSet")) { for (String value : values) { propertyNode.propGroupSet.add(value); } } else if (name.equals("paramMap")) { ContentValues paramMap = propertyNode.paramMap; Set<String> paramMap_TYPE = propertyNode.paramMap_TYPE; for (String value : values) { String[] tmp = value.split("=", 2); String mapKey = tmp[0]; // \, -> , // \\ -> \ // In String#replaceAll(), "\\\\" means a single backslash. String mapValue = tmp[1].replaceAll("\\\\,", ",").replaceAll("\\\\\\\\", "\\\\"); if (mapKey.equalsIgnoreCase("TYPE")) { paramMap_TYPE.add(mapValue); } else { paramMap.put(mapKey, mapValue); } } } else if (name.equals("propValue")) { StringBuilder builder = new StringBuilder(); List<String> list = propertyNode.propValue_vector; int length = values.length; for (int i = 0; i < length; i++) { String normValue = values[i].replaceAll("\\\\,", ",").replaceAll("\\\\\\\\", "\\\\"); list.add(normValue); builder.append(normValue); if (i < length - 1) { builder.append(";"); } } propertyNode.propValue = builder.toString(); } } // At this time, QUOTED-PRINTABLE is already decoded to Java String. // We just need to decode BASE64 String to binary. String encoding = propertyNode.paramMap.getAsString("ENCODING"); if (encoding != null && (encoding.equalsIgnoreCase("BASE64") || encoding.equalsIgnoreCase("B"))) { propertyNode.propValue_bytes = Base64.decodeBase64(propertyNode.propValue_vector.get(0).getBytes()); } return propertyNode; }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void setAuthorFavorite(boolean isFavorite, boolean mustBeFavorite, String author, Context context) {/*from w ww. ja v a2 s.c om*/ if (isFavorite && mustBeFavorite || !isFavorite && !mustBeFavorite) return; DBHelper dbhelper = new DBHelper(context); SQLiteDatabase dbwrite = dbhelper.getWritableDatabase(); if (isFavorite && !mustBeFavorite) { // Remove from the table dbwrite.execSQL("DELETE FROM favorite_users WHERE name=" + esc(author)); } else if (!isFavorite && mustBeFavorite) { // Insert into the table ContentValues cv = new ContentValues(); cv.put("name", author); dbwrite.insert("favorite_users", null, cv); } dbwrite.close(); dbhelper.close(); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static void banUser(String decodedfrom, Context context) { DBHelper db = new DBHelper(context); SQLiteDatabase dbwrite = db.getWritableDatabase(); Cursor c = dbwrite.rawQuery("SELECT _id FROM banned_users " + " WHERE name=" + esc(decodedfrom), null); if (c.getCount() > 0) { c.moveToFirst();//from w w w . ja v a 2 s . c o m dbwrite.execSQL("UPDATE banned_users SET bandisabled=0 WHERE _id=" + c.getInt(0)); } else { ContentValues cv = new ContentValues(); cv.put("name", decodedfrom); cv.put("bandisabled", 0); dbwrite.insert("banned_users", null, cv); } // Mark all the user posts as read, so they get deleted later dbwrite.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis() + " WHERE from_header=" + esc(decodedfrom)); c.close(); dbwrite.close(); db.close(); }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static long insertArticleToGroupID(int groupID, Article articleInfo, String finalRefs, String finalFrom, String finalSubject, Context context, SQLiteDatabase catchedDB) { // The called can create a single SQLiteDatabase object to avoid too many object // creations if we're inside a loop DBHelper db = null;//from w ww.j av a 2s .c o m SQLiteDatabase dbwrite = null; if (catchedDB == null) { db = new DBHelper(context); dbwrite = db.getWritableDatabase(); } else { dbwrite = catchedDB; } ContentValues cv = new ContentValues(); cv.put("subscribed_group_id", groupID); cv.put("reference_list", finalRefs); cv.put("server_article_id", articleInfo.getArticleId()); cv.put("date", articleInfo.getDate()); cv.put("server_article_number", articleInfo.getArticleNumber()); cv.put("from_header", finalFrom); cv.put("subject_header", finalSubject); cv.put("read", 0); cv.put("catched", 0); long ret = dbwrite.insert("headers", null, cv); if (catchedDB == null) { dbwrite.close(); db.close(); } return ret; }