List of usage examples for android.content ContentValues getAsString
public String getAsString(String key)
From source file:com.money.manager.ex.reports.CategoriesReportFragment.java
private CategorySub getCategoryFromSelectedItem(ListView l, int position) { // Reading item from the list view, not adapter! Object item = l.getItemAtPosition(position); if (item == null) return null; Cursor cursor = (Cursor) item; ContentValues values = new ContentValues(); DatabaseUtils.cursorIntToContentValues(cursor, ViewMobileData.CATEGID, values); DatabaseUtils.cursorStringToContentValues(cursor, ViewMobileData.Category, values); DatabaseUtils.cursorIntToContentValues(cursor, ViewMobileData.SubcategID, values); DatabaseUtils.cursorStringToContentValues(cursor, ViewMobileData.Subcategory, values); CategorySub result = new CategorySub(); result.categId = values.getAsInteger(ViewMobileData.CATEGID); result.categName = values.getAsString(ViewMobileData.Category); result.subCategId = values.getAsInteger(ViewMobileData.SubcategID); result.subCategName = values.getAsString(ViewMobileData.Subcategory); return result; }
From source file:at.bitfire.davdroid.resource.LocalCalendar.java
void populateAttendee(Event event, ContentValues values) { try {//from w w w . j av a2 s. c o m final Attendee attendee; final String email = values.getAsString(Attendees.ATTENDEE_EMAIL), idNS = values.getAsString(Attendees.ATTENDEE_ID_NAMESPACE), id = values.getAsString(Attendees.ATTENDEE_IDENTITY); if (idNS != null || id != null) { // attendee identified by namespace and ID attendee = new Attendee(new URI(idNS, id, null)); if (email != null) attendee.getParameters().add(new iCalendar.Email(email)); } else // attendee identified by email address attendee = new Attendee(new URI("mailto", email, null)); final ParameterList params = attendee.getParameters(); String cn = values.getAsString(Attendees.ATTENDEE_NAME); if (cn != null) params.add(new Cn(cn)); // type int type = values.getAsInteger(Attendees.ATTENDEE_TYPE); params.add((type == Attendees.TYPE_RESOURCE) ? CuType.RESOURCE : CuType.INDIVIDUAL); // role int relationship = values.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP); switch (relationship) { case Attendees.RELATIONSHIP_ORGANIZER: case Attendees.RELATIONSHIP_ATTENDEE: case Attendees.RELATIONSHIP_PERFORMER: case Attendees.RELATIONSHIP_SPEAKER: params.add((type == Attendees.TYPE_REQUIRED) ? Role.REQ_PARTICIPANT : Role.OPT_PARTICIPANT); params.add(new Rsvp(true)); break; case Attendees.RELATIONSHIP_NONE: params.add(Role.NON_PARTICIPANT); } // status switch (values.getAsInteger(Attendees.ATTENDEE_STATUS)) { case Attendees.ATTENDEE_STATUS_INVITED: params.add(PartStat.NEEDS_ACTION); break; case Attendees.ATTENDEE_STATUS_ACCEPTED: params.add(PartStat.ACCEPTED); break; case Attendees.ATTENDEE_STATUS_DECLINED: params.add(PartStat.DECLINED); break; case Attendees.ATTENDEE_STATUS_TENTATIVE: params.add(PartStat.TENTATIVE); break; } event.getAttendees().add(attendee); } catch (URISyntaxException ex) { Log.e(TAG, "Couldn't parse attendee information, ignoring", ex); } }
From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java
private void displayMessagesNotification(final Context context, final ContentValues[] values) { final Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH)); final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image); final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED); final Bundle delete_extras = new Bundle(); delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_DIRECT_MESSAGES); delete_intent.putExtras(delete_extras); final Intent content_intent; int notified_count = 0; for (final ContentValues value : values) { final String screen_name = value.getAsString(DirectMessages.SENDER_SCREEN_NAME); final ParcelableDirectMessage message = new ParcelableDirectMessage(value); mNewMessages.add(message);/*from www . j a va 2 s. co m*/ mNewMessageScreenNames.add(screen_name); mNewMessageAccounts.add(message.account_id); notified_count++; } Collections.sort(mNewMessages); final int messages_size = mNewMessages.size(); if (notified_count == 0 || messages_size == 0 || mNewMessageScreenNames.size() == 0) return; final String title; if (messages_size > 1) { builder.setNumber(messages_size); } final int screen_names_size = mNewMessageScreenNames.size(); final ParcelableDirectMessage message = mNewMessages.get(0); if (messages_size == 1) { final Uri.Builder uri_builder = new Uri.Builder(); final long account_id = message.account_id; final long conversation_id = message.sender_id; uri_builder.scheme(SCHEME_TWIDERE); uri_builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION); uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(account_id)); uri_builder.appendQueryParameter(QUERY_PARAM_CONVERSATION_ID, String.valueOf(conversation_id)); content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build()); } else { content_intent = new Intent(context, HomeActivity.class); content_intent.setAction(Intent.ACTION_MAIN); content_intent.addCategory(Intent.CATEGORY_LAUNCHER); final Bundle content_extras = new Bundle(); content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MESSAGES); content_intent.putExtras(content_extras); } if (screen_names_size > 1) { title = res.getString(R.string.notification_direct_message_multiple, display_screen_name ? "@" + message.sender_screen_name : message.sender_name, screen_names_size - 1); } else { title = res.getString(R.string.notification_direct_message, display_screen_name ? "@" + message.sender_screen_name : message.sender_name); } final String text_plain = message.text_plain; final String profile_image_url_string = message.sender_profile_image_url_string; final File profile_image_file = mProfileImageLoader.getCachedImageFile( display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string) : profile_image_url_string); final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width); final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height); final Bitmap profile_image = profile_image_file != null && profile_image_file.isFile() ? BitmapFactory.decodeFile(profile_image_file.getPath()) : null; final Bitmap profile_image_fallback = BitmapFactory.decodeResource(res, R.drawable.ic_profile_image_default); builder.setLargeIcon(Bitmap .createScaledBitmap(profile_image != null ? profile_image : profile_image_fallback, w, h, true)); buildNotification(builder, title, title, text_plain, R.drawable.ic_stat_direct_message, null, content_intent, delete_intent); final StringBuilder summary = new StringBuilder(); final int accounts_count = mNewMessageAccounts.size(); if (accounts_count > 0) { for (int i = 0; i < accounts_count; i++) { final String name = display_screen_name ? "@" + getAccountScreenName(context, mNewMessageAccounts.get(i)) : getAccountName(context, mNewMessageAccounts.get(i)); summary.append(name); if (i != accounts_count - 1) { summary.append(", "); } } } if (messages_size > 1) { final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder); final int max = Math.min(4, messages_size); for (int i = 0; i < max; i++) { final ParcelableDirectMessage s = mNewMessages.get(i); final String name = display_screen_name ? "@" + s.sender_screen_name : s.sender_name; style.addLine(Html.fromHtml("<b>" + name + "</b>: " + s.text_plain)); } if (max == 4 && messages_size - max > 0) { style.addLine(context.getString(R.string.and_more, messages_size - max)); } style.setSummaryText(summary); mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, style.build()); } else { final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder); style.bigText(message.text_plain); style.setSummaryText(summary); mNotificationManager.notify(NOTIFICATION_ID_DIRECT_MESSAGES, style.build()); } }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
@VisibleForTesting void reportClickAtTime(SuggestionCursor suggestion, int position, long now) { suggestion.moveTo(position);// w ww .j a v a 2 s. co m if (DBG) { Log.d(TAG, "logClicked(" + suggestion + ")"); } if (SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT.equals(suggestion.getShortcutId())) { if (DBG) Log.d(TAG, "clicked suggestion requested not to be shortcuted"); return; } Corpus corpus = mCorpora.getCorpusForSource(suggestion.getSuggestionSource()); if (corpus == null) { Log.w(TAG, "no corpus for clicked suggestion"); return; } // Once the user has clicked on a shortcut, don't bother refreshing // (especially if this is a new shortcut) mRefresher.markShortcutRefreshed(suggestion.getSuggestionSource(), suggestion.getShortcutId()); // Add or update suggestion info // Since intent_key is the primary key, any existing // suggestion with the same source+data+action will be replaced final ContentValues shortcut = makeShortcutRow(suggestion); String intentKey = shortcut.getAsString(Shortcuts.intent_key.name()); // Log click for shortcut final ContentValues click = new ContentValues(); click.put(ClickLog.intent_key.name(), intentKey); click.put(ClickLog.query.name(), suggestion.getUserQuery()); click.put(ClickLog.hit_time.name(), now); click.put(ClickLog.corpus.name(), corpus.getName()); runTransactionAsync(new SQLiteTransaction() { @Override protected boolean performTransaction(SQLiteDatabase db) { if (DBG) Log.d(TAG, "Adding shortcut: " + shortcut); db.replaceOrThrow(Shortcuts.TABLE_NAME, null, shortcut); db.insertOrThrow(ClickLog.TABLE_NAME, null, click); return true; } }); }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Parse a content.//w ww . j a va 2s . co m * @param values content as returned by the storage. * @return content. * @throws Exception parsing problem, most likely invalid XML. */ private CapptainReachContent parseContent(ContentValues values) throws Exception { /* Parse the first XML tag */ CapptainReachContent content = parseContent(values.getAsString(XML), values.getAsString(JID)); content.setState(values); /* Set local id */ content.setLocalId(values.getAsLong(ID)); return content; }
From source file:com.github.michalbednarski.intentslab.providerlab.AdvancedQueryActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.advanced_query); Intent intent = getIntent();/*from w ww .jav a 2 s . com*/ Bundle instanceStateOrExtras = savedInstanceState != null ? savedInstanceState : intent.getExtras(); if (instanceStateOrExtras == null) { instanceStateOrExtras = Bundle.EMPTY; } // Uri mUriTextView = (AutoCompleteTextView) findViewById(R.id.uri); if (intent.getData() != null) { mUriTextView.setText(intent.getDataString()); } mUriTextView.setAdapter(new UriAutocompleteAdapter(this)); // Projection { mSpecifyProjectionCheckBox = (CheckBox) findViewById(R.id.specify_projection); mProjectionLayout = (LinearLayout) findViewById(R.id.projection_columns); // Bind events for master CheckBox and add new button findViewById(R.id.new_projection_column).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new UserProjectionColumn(""); } }); mSpecifyProjectionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mProjectionLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); // Get values to fill String[] availableProjectionColumns = intent.getStringArrayExtra(EXTRA_PROJECTION_AVAILABLE_COLUMNS); String[] specifiedProjectionColumns = instanceStateOrExtras.getStringArray(EXTRA_PROJECTION); if (specifiedProjectionColumns == null) { mSpecifyProjectionCheckBox.setChecked(false); } if (availableProjectionColumns != null && availableProjectionColumns.length == 0) { availableProjectionColumns = null; } if (availableProjectionColumns != null && specifiedProjectionColumns == null) { specifiedProjectionColumns = availableProjectionColumns; } // Create available column checkboxes int i = 0; if (availableProjectionColumns != null) { for (String availableProjectionColumn : availableProjectionColumns) { boolean isChecked = i < specifiedProjectionColumns.length && availableProjectionColumn.equals(specifiedProjectionColumns[i]); new DefaultProjectionColumn(availableProjectionColumn, isChecked); if (isChecked) { i++; } } } // Create user column text fields if (specifiedProjectionColumns != null && i < specifiedProjectionColumns.length) { for (int il = specifiedProjectionColumns.length; i < il; i++) { new UserProjectionColumn(specifiedProjectionColumns[i]); } } } // Selection { // Find views mSelectionCheckBox = (CheckBox) findViewById(R.id.selection_header); mSelectionText = (TextView) findViewById(R.id.selection); mSelectionLayout = findViewById(R.id.selection_layout); mSelectionArgsTable = (TableLayout) findViewById(R.id.selection_args); // Bind events for add button and master CheckBox findViewById(R.id.selection_add_arg).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new SelectionArg("", true); } }); mSelectionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mSelectionLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); // Fill selection text view and CheckBox String selection = intent.getStringExtra(EXTRA_SELECTION); String[] selectionArgs = instanceStateOrExtras.getStringArray(EXTRA_SELECTION_ARGS); mSelectionCheckBox.setChecked(selection != null); if (selection != null) { mSelectionText.setText(selection); } // Fill selection arguments if ((selection != null || savedInstanceState != null) && selectionArgs != null && selectionArgs.length != 0) { for (String selectionArg : selectionArgs) { new SelectionArg(selectionArg); } } } // Content values { // Find views mContentValuesHeader = (TextView) findViewById(R.id.content_values_header); mContentValuesTable = (TableLayout) findViewById(R.id.content_values); mContentValuesTableHeader = (TableRow) findViewById(R.id.content_values_table_header); // Bind add new button event findViewById(R.id.new_content_value).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new ContentValue("", "", true); } }); // Create table ContentValues contentValues = instanceStateOrExtras.getParcelable(EXTRA_CONTENT_VALUES); if (contentValues != null) { contentValues.valueSet(); for (String key : Utils.getKeySet(contentValues)) { new ContentValue(key, contentValues.getAsString(key)); } } } // Order { // Find views mSpecifyOrderCheckBox = (CheckBox) findViewById(R.id.specify_order); mOrderTextView = (TextView) findViewById(R.id.order); // Bind events mSpecifyOrderCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mOrderTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); // Fill fields String order = intent.getStringExtra(EXTRA_SORT_ORDER); if (order == null) { mSpecifyOrderCheckBox.setChecked(false); } else { mOrderTextView.setText(order); } } // Method (affects previous views so they must be initialized first) mMethodSpinner = (Spinner) findViewById(R.id.method); mMethodSpinner .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, METHOD_NAMES)); mMethodSpinner.setOnItemSelectedListener(onMethodSpinnerItemSelectedListener); mMethodSpinner.setSelection(intent.getIntExtra(EXTRA_METHOD, METHOD_QUERY)); }
From source file:com.hivewallet.androidclient.wallet.AddressBookProvider.java
@Override public Uri insert(final Uri uri, final ContentValues values) { if (uri.getPathSegments().size() != 1) throw new IllegalArgumentException(uri.toString()); final String address = uri.getLastPathSegment(); values.put(KEY_ADDRESS, address);// ww w .ja va2 s . co m long rowId = helper.getWritableDatabase().insertOrThrow(DATABASE_TABLE, null, values); final Uri rowUri = contentUri(getContext().getPackageName()).buildUpon().appendPath(address) .appendPath(Long.toString(rowId)).build(); String photo = values.getAsString(KEY_PHOTO); if (photo != null) helper.setPhotoAssetAsPermanent(photo, true); getContext().getContentResolver().notifyChange(rowUri, null); return rowUri; }
From source file:org.ohmage.db.DbHelper.java
/** * Adds a response to the feedback database. * //from w w w. ja va 2s . c o m * @return the ID of the inserted record, or -1 if unsuccessful */ public long addResponseRow(SQLiteDatabase db, ContentValues values) { long rowId = -1; // extract data that we'll need to parse the json + insert prompt // responses String response = values.getAsString(Responses.RESPONSE_JSON); String campaignUrn = values.getAsString(Responses.CAMPAIGN_URN); String surveyId = values.getAsString(Responses.SURVEY_ID); try { // start a transaction involving the following operations: // 1) insert feedback response row // 2) parse json-encoded responses and insert one row into prompts // per entry db.beginTransaction(); // do the actual insert into feedback responses rowId = db.insert(Tables.RESPONSES, null, values); // check if it succeeded; if not, we can't do anything if (rowId == -1) return -1; if (populatePromptsFromResponseJSON(db, rowId, response, campaignUrn, surveyId)) { // and we're done; finalize the transaction db.setTransactionSuccessful(); } // else we fail and the transaction gets rolled back } catch (SQLiteConstraintException e) { Log.e(TAG, "Attempted to insert record that violated a SQL constraint (likely the hashcode)"); return -1; } catch (Exception e) { Log.e(TAG, "Generic exception thrown from db insert", e); return -1; } finally { db.endTransaction(); // db.close(); } return rowId; }
From source file:com.tct.mail.providers.Attachment.java
/** * Create an attachment from a {@link ContentValues} object. * The keys should be {@link AttachmentColumns}. *//* w w w.j av a2s . com*/ public Attachment(ContentValues values) { name = values.getAsString(AttachmentColumns.NAME); size = values.getAsInteger(AttachmentColumns.SIZE); uri = parseOptionalUri(values.getAsString(AttachmentColumns.URI)); contentType = values.getAsString(AttachmentColumns.CONTENT_TYPE); state = values.getAsInteger(AttachmentColumns.STATE); destination = values.getAsInteger(AttachmentColumns.DESTINATION); downloadedSize = values.getAsInteger(AttachmentColumns.DOWNLOADED_SIZE); contentUri = parseOptionalUri(values.getAsString(AttachmentColumns.CONTENT_URI)); thumbnailUri = parseOptionalUri(values.getAsString(AttachmentColumns.THUMBNAIL_URI)); previewIntentUri = parseOptionalUri(values.getAsString(AttachmentColumns.PREVIEW_INTENT_URI)); providerData = values.getAsString(AttachmentColumns.PROVIDER_DATA); supportsDownloadAgain = values.getAsBoolean(AttachmentColumns.SUPPORTS_DOWNLOAD_AGAIN); type = values.getAsInteger(AttachmentColumns.TYPE); flags = values.getAsInteger(AttachmentColumns.FLAGS); partId = values.getAsString(AttachmentColumns.CONTENT_ID); //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_S contentId = values.getAsString(AttachmentColumns.CONTENT_ID); //TS: wenggangjin 2014-12-10 EMAIL BUGFIX_852100 MOD_E //TS: zhonghua.tuo 2015-3-3 EMAIL BUGFIX_936728 ADD_S realUri = parseOptionalUri(values.getAsString(AttachmentColumns.REAL_URI)); //TS: zhonghua.tuo 2015-3-3 EMAIL BUGFIX_936728 ADD_E // TS: Gantao 2015-09-19 EMAIL BUGFIX_570084 ADD_S isInline = values.getAsInteger(AttachmentColumns.ISINLINE); // TS: Gantao 2015-09-19 EMAIL BUGFIX_570084 ADD_E }
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
protected void populateNote(Contact c, ContentValues row) { c.note = row.getAsString(Note.NOTE); }