List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:org.mythtv.service.content.v25.LiveStreamHelperV25.java
private boolean save(final Context context, final LocationProfile locationProfile, LiveStreamInfo liveStreamInfo, int channelId, DateTime startTime) { Log.d(TAG, "save : enter"); if (null == context) throw new RuntimeException("LiveStreamHelperV25 is not initialized"); DateTime lastModified = new DateTime(DateTimeZone.UTC); boolean saved = false; ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStreamInfo, lastModified, channelId, startTime);//from ww w. ja va2 s . c o m String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStreamInfo.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "save : updating existing liveStream info"); long id = cursor.getLong( cursor.getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); int updated = context.getContentResolver() .update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); if (updated == 1) { saved = true; } } else { Log.v(TAG, "save : inserting new liveStream info"); Uri url = context.getContentResolver().insert(LiveStreamConstants.CONTENT_URI, values); if (ContentUris.parseId(url) > 0) { saved = true; } } cursor.close(); Log.d(TAG, "save : exit"); return saved; }
From source file:org.mythtv.service.content.v26.LiveStreamHelperV26.java
private boolean save(final Context context, final LocationProfile locationProfile, LiveStreamInfo liveStreamInfo, int channelId, DateTime startTime) { Log.d(TAG, "save : enter"); if (null == context) throw new RuntimeException("LiveStreamHelperV26 is not initialized"); DateTime lastModified = new DateTime(DateTimeZone.UTC); boolean saved = false; ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStreamInfo, lastModified, channelId, startTime);//from www. ja v a2s .c o m String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStreamInfo.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "save : updating existing liveStream info"); long id = cursor.getLong( cursor.getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); int updated = context.getContentResolver() .update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); if (updated == 1) { saved = true; } } else { Log.v(TAG, "save : inserting new liveStream info"); Uri url = context.getContentResolver().insert(LiveStreamConstants.CONTENT_URI, values); if (ContentUris.parseId(url) > 0) { saved = true; } } cursor.close(); Log.d(TAG, "save : exit"); return saved; }
From source file:org.mythtv.service.content.v27.LiveStreamHelperV27.java
private boolean save(final Context context, final LocationProfile locationProfile, LiveStreamInfo liveStreamInfo, int channelId, DateTime startTime) { Log.d(TAG, "save : enter"); if (null == context) throw new RuntimeException("LiveStreamHelperV27 is not initialized"); DateTime lastModified = new DateTime(DateTimeZone.UTC); boolean saved = false; ContentValues values = convertLiveStreamInfoToContentValues(locationProfile, liveStreamInfo, lastModified, channelId, startTime);// w ww . jav a 2 s . co m String[] projection = new String[] { LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID }; String selection = LiveStreamConstants.FIELD_ID + " = ?"; String[] selectionArgs = new String[] { String.valueOf(liveStreamInfo.getId()) }; selection = appendLocationHostname(context, locationProfile, selection, LiveStreamConstants.TABLE_NAME); Cursor cursor = context.getContentResolver().query(LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null); if (cursor.moveToFirst()) { Log.v(TAG, "save : updating existing liveStream info"); long id = cursor.getLong( cursor.getColumnIndexOrThrow(LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID)); int updated = context.getContentResolver() .update(ContentUris.withAppendedId(LiveStreamConstants.CONTENT_URI, id), values, null, null); if (updated == 1) { saved = true; } } else { Log.v(TAG, "save : inserting new liveStream info"); Uri url = context.getContentResolver().insert(LiveStreamConstants.CONTENT_URI, values); if (ContentUris.parseId(url) > 0) { saved = true; } } cursor.close(); Log.d(TAG, "save : exit"); return saved; }
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).)//from w w w .jav a 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.abcvoipsip.ui.dialpad.DialerFragment.java
@Override public void placeVMCall() { Long accountToUse = SipProfile.INVALID_ID; SipProfile acc = null;// w ww . j av a2s. c o m acc = accountChooserButton.getSelectedAccount(); if (acc != null) { accountToUse = acc.id; } if (accountToUse >= 0) { SipProfile vmAcc = SipProfile.getProfileFromDbId(getActivity(), acc.id, new String[] { SipProfile.FIELD_VOICE_MAIL_NBR }); if (!TextUtils.isEmpty(vmAcc.vm_nbr)) { // Account already have a VM number try { service.makeCall(vmAcc.vm_nbr, (int) acc.id); } catch (RemoteException e) { Log.e(THIS_FILE, "Service can't be called to make the call"); } } else { // Account has no VM number, propose to create one final long editedAccId = acc.id; LayoutInflater factory = LayoutInflater.from(getActivity()); final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null); missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(acc.display_name) .setView(textEntryView) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (missingVoicemailDialog != null) { TextView tf = (TextView) missingVoicemailDialog.findViewById(R.id.vmfield); if (tf != null) { String vmNumber = tf.getText().toString(); if (!TextUtils.isEmpty(vmNumber)) { ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_VOICE_MAIL_NBR, vmNumber); int updated = getActivity().getContentResolver() .update(ContentUris.withAppendedId( SipProfile.ACCOUNT_ID_URI_BASE, editedAccId), cv, null, null); Log.d(THIS_FILE, "Updated accounts " + updated); } } missingVoicemailDialog.hide(); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (missingVoicemailDialog != null) { missingVoicemailDialog.hide(); } } }).create(); // When the dialog is up, completely hide the in-call UI // underneath (which is in a partially-constructed state). missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); missingVoicemailDialog.show(); } } else if (accountToUse == CallHandler.getAccountIdForCallHandler(getActivity(), "com.abcvoipsip/com.abcvoipsip.plugins.telephony.CallHandler")) { // Case gsm voice mail TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); String vmNumber = tm.getVoiceMailNumber(); if (!TextUtils.isEmpty(vmNumber)) { OutgoingCall.ignoreNext = vmNumber; Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", vmNumber, null)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else { missingVoicemailDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.gsm) .setMessage(R.string.no_voice_mail_configured) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (missingVoicemailDialog != null) { missingVoicemailDialog.hide(); } } }).create(); // When the dialog is up, completely hide the in-call UI // underneath (which is in a partially-constructed state). missingVoicemailDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); missingVoicemailDialog.show(); } } // TODO : manage others ?... for now, no way to do so cause no vm stored }
From source file:io.n7.calendar.caldav.CalDAVService.java
private VEvent getEvFromDB(String uid, long id) { String[] proj = { Events.TITLE, //0 Events.DESCRIPTION, //1 Events.DTSTART, //2 Events.DTEND, //3 Events.EVENT_TIMEZONE, //4 Events.DURATION, //5 Events.EVENT_LOCATION }; //6 Cursor c = mCR.query(ContentUris.withAppendedId(EVENTS_URI, id), proj, null, null, null); if (c.moveToFirst()) { VEvent ve = new VEvent(); ve.getProperties().add(new Summary(c.getString(0))); ve.getProperties().add(new Description(c.getString(1))); ve.getProperties().add(new DtStart(new DateTime(c.getLong(2)))); ve.getProperties().add(new TzId(c.getString(4))); ve.getProperties().add(new Location(c.getString(6))); long tl = c.getLong(3); if (tl > 0) { ve.getProperties().add(new DtEnd(new DateTime(tl))); Log.d(TAG, "dt end " + tl); } else {//w w w.j a v a 2s . c o m String ts = c.getString(4); Log.d(TAG, "dur " + ts); if (ts != null) { net.fortuna.ical4j.model.property.Duration dur = new net.fortuna.ical4j.model.property.Duration(); dur.setValue(ts); ve.getProperties().add(dur); } } ve.getProperties().add(new Uid(uid)); return ve; } else return null; }
From source file:com.kyakujin.android.autoeco.ui.MainActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info; try {/*from w w w .j a v a2 s . c o m*/ info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG, "bad AdapterContextMenuInfo", e); return false; } mCurrentSchedUri = ContentUris.withAppendedId(SchedTbl.CONTENT_URI, info.id); switch (item.getItemId()) { case R.id.context_delete: // ? AlertDialog dlg = new AlertDialog.Builder(this).setTitle(R.string.alert_title_delete) .setIcon(android.R.drawable.ic_dialog_alert).setMessage(R.string.alert_message_delete_sched) .setPositiveButton("YES", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // ??? SchedModel model = new SchedModel(); model.setId(Integer.valueOf(mCurrentSchedUri.getLastPathSegment())); SchedAlarmManager am = new SchedAlarmManager(mActivity); am.cancelAlarm(model); // DB?? SchedDAO dao = new SchedDAO(mActivity); dao.deleteSchedById(Integer.valueOf(mCurrentSchedUri.getLastPathSegment())); mCurrentSchedUri = null; // ???? // NOTE:????????? activityRestart(); } }).setNegativeButton("NO", null).setInverseBackgroundForced(true).create(); dlg.show(); return true; case R.id.context_edit: setTime(); // mManager.restartLoader(Query.LOADER_ID, null, this); return true; default: return super.onContextItemSelected(item); } }
From source file:com.android.exchange.EasAccountService.java
private void pushFallback(long mailboxId) { Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId); if (mailbox == null) { return;/* w w w. ja v a 2 s . c om*/ } ContentValues cv = new ContentValues(); int mins = PING_FALLBACK_PIM; if (mailbox.mType == Mailbox.TYPE_INBOX) { mins = PING_FALLBACK_INBOX; } cv.put(Mailbox.SYNC_INTERVAL, mins); mContentResolver.update(ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId), cv, null, null); errorLog("*** PING ERROR LOOP: Set " + mailbox.mDisplayName + " to " + mins + " min sync"); ExchangeService.kick("push fallback"); }
From source file:com.haibison.android.anhuu.utils.ui.bookmark.BookmarkFragment.java
/** * Shows a dialog to let the user enter new name or change current name of a * bookmark.//from w w w .jav a 2 s. c om * * @param context * {@link Context} * @param providerId * the provider ID. * @param id * the bookmark ID. * @param uri * the URI to the bookmark. * @param name * the name. To enter new name, this is the suggested name you * provide. To rename, this is the old name. */ public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id, final Uri uri, final String name) { final AlertDialog dialog = Dlg.newAlertDlg(context); View view = LayoutInflater.from(context).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null); final EditText textName = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1); textName.setText(name); textName.selectAll(); textName.setHint(R.string.anhuu_f5be488d_hint_new_name); textName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { UI.showSoftKeyboard(textName, false); Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE); if (btn.isEnabled()) btn.performClick(); return true; } return false; }// onEditorAction() }); dialog.setView(view); dialog.setIcon(R.drawable.anhuu_f5be488d_bookmarks_dark); dialog.setTitle(id < 0 ? R.string.anhuu_f5be488d_title_new_bookmark : R.string.anhuu_f5be488d_title_rename); dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newName = textName.getText().toString().trim(); if (android.text.TextUtils.isEmpty(newName)) { Dlg.toast(context, R.string.anhuu_f5be488d_msg_bookmark_name_is_invalid, Dlg.LENGTH_SHORT); return; } UI.showSoftKeyboard(textName, false); ContentValues values = new ContentValues(); values.put(BookmarkContract.COLUMN_NAME, newName); if (id >= 0) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( ContentUris.withAppendedId(BookmarkContract.genContentIdUriBase(context), id), values, null, null); } else { /* * Check if the URI exists or doesn't. If it exists, * update it instead of inserting the new one. */ Cursor cursor = context.getContentResolver().query( BookmarkContract.genContentUri(context), null, String.format("%s = %s AND %s LIKE %s", BookmarkContract.COLUMN_PROVIDER_ID, DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.COLUMN_URI, DatabaseUtils.sqlEscapeString(uri.toString())), null, null); try { if (cursor != null && cursor.moveToFirst()) { values.put(BookmarkContract.COLUMN_MODIFICATION_TIME, DbUtils.formatNumber(new Date().getTime())); context.getContentResolver().update( Uri.withAppendedPath(BookmarkContract.genContentIdUriBase(context), Uri.encode(cursor.getString( cursor.getColumnIndex(BookmarkContract._ID)))), values, null, null); } else { values.put(BookmarkContract.COLUMN_PROVIDER_ID, providerId); values.put(BookmarkContract.COLUMN_URI, uri.toString()); context.getContentResolver().insert(BookmarkContract.genContentUri(context), values); } } finally { if (cursor != null) cursor.close(); } } Dlg.toast(context, context.getString(R.string.anhuu_f5be488d_msg_done), Dlg.LENGTH_SHORT); }// onClick() }); dialog.show(); UI.showSoftKeyboard(textName, true); final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE); buttonOk.setEnabled(id < 0); textName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { String newName = s.toString().trim(); boolean enabled = !android.text.TextUtils.isEmpty(newName); buttonOk.setEnabled(enabled); /* * If renaming, only enable button OK if new name is not equal * to the old one. */ if (enabled && id >= 0) buttonOk.setEnabled(!newName.equals(name)); } }); }
From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static String getPath(final Context context, final Uri uri) { final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }/*from w w w .ja va2 s . c o m*/ } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { // Return the remote address if (isGooglePhotosUri(uri)) return uri.getLastPathSegment(); return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }