List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.akop.bach.parser.PsnUsParser.java
protected void parseTrophies(PsnAccount account, long gameId) throws ParserException, IOException { // Find game record in local DB ContentResolver cr = mContext.getContentResolver(); String gameUid = Games.getUid(mContext, gameId); List<NameValuePair> inputs = new ArrayList<NameValuePair>(); inputs.add(new BasicNameValuePair("sortBy", "id_asc")); inputs.add(new BasicNameValuePair("titleId", gameUid)); String page = getResponse(String.format(URL_TROPHIES, URLEncoder.encode(account.getScreenName(), "UTF-8")), inputs, true);//w ww. ja va2 s.co m int index = 0; long started = System.currentTimeMillis(); Matcher achievements = PATTERN_TROPHIES.matcher(page); Matcher m; List<ContentValues> cvList = new ArrayList<ContentValues>(100); while (achievements.find()) { String trophyRow = achievements.group(2); String title = mContext.getString(R.string.secret_trophy); if ((m = PATTERN_TROPHY_TITLE.matcher(trophyRow)).find()) title = htmlDecode(m.group(1)); String description = mContext.getString(R.string.this_is_a_secret_trophy); if ((m = PATTERN_TROPHY_DESCRIPTION.matcher(trophyRow)).find()) description = htmlDecode(m.group(1)); String iconUrl = null; if ((m = PATTERN_TROPHY_ICON.matcher(trophyRow)).find()) iconUrl = getAvatarImage(m.group(1)); long earned = 0; if ((m = PATTERN_TROPHY_EARNED.matcher(trophyRow)).find()) { try { earned = TROPHY_DATE_FORMAT.parse(m.group(1)).getTime(); } catch (ParseException e) { if (App.getConfig().logToConsole()) e.printStackTrace(); } } boolean isSecret = false; int type = 0; if ((m = PATTERN_TROPHY_TYPE.matcher(trophyRow)).find()) { String trophyType = m.group(1).toUpperCase(); if (trophyType.equals("BRONZE")) type = PSN.TROPHY_BRONZE; else if (trophyType.equals("SILVER")) type = PSN.TROPHY_SILVER; else if (trophyType.equals("GOLD")) type = PSN.TROPHY_GOLD; else if (trophyType.equals("PLATINUM")) type = PSN.TROPHY_PLATINUM; else if (trophyType.equals("HIDDEN")) isSecret = true; } ContentValues cv = new ContentValues(20); cv.put(Trophies.TITLE, title); cv.put(Trophies.DESCRIPTION, description); cv.put(Trophies.SORT_ORDER, index); cv.put(Trophies.EARNED, earned); cv.put(Trophies.ICON_URL, iconUrl); cv.put(Trophies.GAME_ID, gameId); cv.put(Trophies.IS_SECRET, isSecret ? 1 : 0); cv.put(Trophies.TYPE, type); cvList.add(cv); index++; } if (App.getConfig().logToConsole()) started = displayTimeTaken("New trophy parsing", started); ContentValues[] cva = new ContentValues[cvList.size()]; cvList.toArray(cva); cr.delete(Trophies.CONTENT_URI, Trophies.GAME_ID + "=" + gameId, null); // Bulk-insert new trophies cr.bulkInsert(Trophies.CONTENT_URI, cva); cr.notifyChange(Trophies.CONTENT_URI, null); if (App.getConfig().logToConsole()) started = displayTimeTaken("New trophy processing", started); // Update the game to remove the 'dirty' attribute ContentValues cv = new ContentValues(10); cv.put(Games.TROPHIES_DIRTY, 0); cr.update(Games.CONTENT_URI, cv, Games._ID + "=" + gameId, null); cr.notifyChange(ContentUris.withAppendedId(Games.CONTENT_URI, gameId), null); if (App.getConfig().logToConsole()) displayTimeTaken("Updating Game", started); }
From source file:com.akop.bach.parser.PsnEuParser.java
@SuppressLint("DefaultLocale") @Override//from ww w.ja v a 2s . c o m protected void parseFriends(PsnAccount account) throws ParserException, IOException { synchronized (PsnEuParser.class) { ContentResolver cr = mContext.getContentResolver(); ContentValues cv; List<ContentValues> newCvs = new ArrayList<ContentValues>(100); final long accountId = account.getId(); int rowsInserted = 0; int rowsUpdated = 0; int rowsDeleted = 0; long updated = System.currentTimeMillis(); long started = updated; // Handle pending requests String page = getResponse(URL_FRIENDS); Matcher m; Matcher friendMatcher = PATTERN_FRIENDS_PENDING.matcher(page); while (friendMatcher.find()) { String onlineId = htmlDecode(friendMatcher.group(1)); Cursor c = cr.query(Friends.CONTENT_URI, FRIEND_ID_PROJECTION, Friends.ACCOUNT_ID + "=" + account.getId() + " AND " + Friends.ONLINE_ID + "=?", new String[] { onlineId }, null); long friendId = -1; try { if (c != null && c.moveToFirst()) friendId = c.getLong(0); } finally { if (c != null) c.close(); } cv = new ContentValues(15); cv.put(Friends.DELETE_MARKER, updated); cv.put(Friends.ONLINE_STATUS, PSN.STATUS_PENDING); if (friendId < 0) { // New cv.put(Friends.ONLINE_ID, onlineId); cv.put(Friends.ACCOUNT_ID, accountId); cv.put(Friends.PROGRESS, 0); cv.putNull(Friends.ICON_URL); cv.put(Friends.LEVEL, 0); cv.put(Friends.TROPHIES_PLATINUM, 0); cv.put(Friends.TROPHIES_GOLD, 0); cv.put(Friends.TROPHIES_SILVER, 0); cv.put(Friends.TROPHIES_BRONZE, 0); cv.putNull(Friends.PLAYING); cv.put(Friends.LAST_UPDATED, 0); newCvs.add(cv); } else { cr.update(ContentUris.withAppendedId(Friends.CONTENT_URI, friendId), cv, null, null); rowsUpdated++; } } // Handle rest of friends page = getResponse(URL_FRIENDS_AJAX); friendMatcher = PATTERN_FRIENDS.matcher(page); while (friendMatcher.find()) { String friendData = friendMatcher.group(1); String onlineId; if (!(m = PATTERN_FRIEND_ONLINE_ID.matcher(friendData)).find()) continue; onlineId = htmlDecode(m.group(1)); int level = 0; if ((m = PATTERN_FRIEND_LEVEL.matcher(friendData)).find()) level = Integer.parseInt(m.group(1)); String iconUrl = null; if ((m = PATTERN_FRIEND_AVATAR.matcher(friendData)).find()) iconUrl = getLargeAvatarIcon(resolveImageUrl(URL_FRIENDS_AJAX, m.group(1))); String comment = null; if ((m = PATTERN_FRIEND_COMMENT.matcher(friendData)).find()) { comment = htmlDecode(m.group(1)); if (comment != null && comment.equals("null")) comment = null; } int memberType = PSN.MEMBER_TYPE_FREE; if ((m = PATTERN_FRIEND_IS_PLUS.matcher(friendData)).find() && m.group(1).equalsIgnoreCase("true")) { memberType = PSN.MEMBER_TYPE_PLUS; } int bronze = 0; int silver = 0; int gold = 0; int platinum = 0; m = PATTERN_FRIEND_TROPHY.matcher(friendData); while (m.find()) { String type = m.group(1).toLowerCase(); if ("bronze".equals(type)) bronze = Integer.parseInt(m.group(2)); else if ("silver".equals(type)) silver = Integer.parseInt(m.group(2)); else if ("gold".equals(type)) gold = Integer.parseInt(m.group(2)); else if ("platinum".equals(type)) platinum = Integer.parseInt(m.group(2)); } boolean inGame = false; int status = PSN.STATUS_OTHER; if ((m = PATTERN_FRIEND_STATUS.matcher(friendData)).find()) { String presence = m.group(1).toLowerCase(); if (presence.equals("offline")) status = PSN.STATUS_OFFLINE; else if (presence.equals("online")) status = PSN.STATUS_ONLINE; else if (presence.equals("online-ingame")) { status = PSN.STATUS_ONLINE; inGame = true; } else if (presence.equals("online-away")) status = PSN.STATUS_AWAY; else if (presence.equals("online-ingame-away")) { status = PSN.STATUS_AWAY; inGame = true; } else if (presence.equals("pending")) status = PSN.STATUS_PENDING; } String playing = null; if ((m = PATTERN_FRIEND_PLAYING.matcher(friendData)).find()) { String activity = htmlDecode(m.group(1)).trim(); if (activity != null && activity.length() > 0) { if (inGame) playing = mContext.getString(R.string.playing_f, activity); else playing = activity; } } Cursor c = cr.query(Friends.CONTENT_URI, FRIEND_ID_PROJECTION, Friends.ACCOUNT_ID + "=" + account.getId() + " AND " + Friends.ONLINE_ID + "=?", new String[] { onlineId }, null); long friendId = -1; try { if (c != null && c.moveToFirst()) friendId = c.getLong(0); } finally { if (c != null) c.close(); } cv = new ContentValues(15); cv.put(Friends.ICON_URL, iconUrl); cv.put(Friends.LEVEL, level); cv.put(Friends.MEMBER_TYPE, memberType); cv.put(Friends.COMMENT, comment); cv.put(Friends.LEVEL, level); cv.put(Friends.ONLINE_STATUS, status); cv.put(Friends.TROPHIES_PLATINUM, platinum); cv.put(Friends.TROPHIES_GOLD, gold); cv.put(Friends.TROPHIES_SILVER, silver); cv.put(Friends.TROPHIES_BRONZE, bronze); cv.put(Friends.PLAYING, playing); cv.put(Friends.DELETE_MARKER, updated); if (friendId < 0) { // New cv.put(Friends.ONLINE_ID, onlineId); cv.put(Friends.ACCOUNT_ID, accountId); cv.put(Friends.PROGRESS, 0); cv.put(Friends.LAST_UPDATED, 0); newCvs.add(cv); } else { cr.update(ContentUris.withAppendedId(Friends.CONTENT_URI, friendId), cv, null, null); rowsUpdated++; } } // Remove friends rowsDeleted = cr.delete(Friends.CONTENT_URI, Friends.ACCOUNT_ID + "=" + accountId + " AND " + Friends.DELETE_MARKER + "!=" + updated, null); if (newCvs.size() > 0) { ContentValues[] cvs = new ContentValues[newCvs.size()]; newCvs.toArray(cvs); rowsInserted = cr.bulkInsert(Friends.CONTENT_URI, cvs); } account.refresh(Preferences.get(mContext)); account.setLastFriendUpdate(System.currentTimeMillis()); account.save(Preferences.get(mContext)); cr.notifyChange(Friends.CONTENT_URI, null); if (App.getConfig().logToConsole()) started = displayTimeTaken("Friend page processing [I:" + rowsInserted + ";U:" + rowsUpdated + ";D:" + rowsDeleted + "]", started); } }
From source file:com.android.providers.downloads.DownloadInfo.java
/** * Query and return status of requested download. *//* w w w .j a va 2s . c om*/ public static int queryDownloadStatus(ContentResolver resolver, long id) { final Cursor cursor = resolver.query( ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id), new String[] { Downloads.Impl.COLUMN_STATUS }, null, null, null); try { if (cursor.moveToFirst()) { return cursor.getInt(0); } else { // TODO: increase strictness of value returned for unknown // downloads; this is safe default for now. return Downloads.Impl.STATUS_PENDING; } } finally { cursor.close(); } }
From source file:edu.mit.mobile.android.locast.data.MediaSync.java
/** * Scans the media database to see if the given item is currently there. If * it is, update the cast media to point to the local content: URI for it. * * @param context/*from w w w.j a v a 2 s .c o m*/ * @param castMedia * Local URI to the cast. * @param pubUri * public URI to the media file. * @return local URI if it exists. * @throws SyncException */ public String checkForMediaEntry(Uri castMedia, Uri pubUri, String mimeType) throws SyncException { final ContentResolver cr = getContentResolver(); String newLocUri = null; final File destfile = getFilePath(pubUri); if (mimeType == null) { throw new SyncException("missing MIME type"); } String[] projection; String selection; Uri contentUri; if (mimeType.startsWith("image/")) { projection = new String[] { Images.Media._ID, Images.Media.DATA }; selection = Images.Media.DATA + "=?"; contentUri = Images.Media.EXTERNAL_CONTENT_URI; } else if (mimeType.startsWith("video/")) { projection = new String[] { Video.Media._ID, Video.Media.DATA }; selection = Video.Media.DATA + "=?"; contentUri = Video.Media.EXTERNAL_CONTENT_URI; } else { throw new SyncException("unknown MIME type: '" + mimeType + "'"); } final String[] selectionArgs = { destfile.getAbsolutePath() }; final Cursor mediaEntry = cr.query(contentUri, projection, selection, selectionArgs, null); try { if (mediaEntry.moveToFirst()) { newLocUri = ContentUris .withAppendedId(contentUri, mediaEntry.getLong(mediaEntry.getColumnIndex(BaseColumns._ID))) .toString(); } } finally { mediaEntry.close(); } if (newLocUri != null) { updateCastMediaLocalUri(castMedia, newLocUri, mimeType); } else { Log.e(TAG, "The media provider doesn't seem to know about " + destfile.getAbsolutePath() + " which is on the filesystem. Strange..."); } return newLocUri; }
From source file:com.tct.email.LegacyConversions.java
/** * Read a complete Provider message into a legacy message (for IMAP upload). This * is basically the equivalent of LocalFolder.getMessages() + LocalFolder.fetch(). *///from w w w . j a v a 2 s. co m public static Message makeMessage(final Context context, final EmailContent.Message localMessage) throws MessagingException { final MimeMessage message = new MimeMessage(); // LocalFolder.getMessages() equivalent: Copy message fields message.setSubject(localMessage.mSubject == null ? "" : localMessage.mSubject); final Address[] from = Address.fromHeader(localMessage.mFrom); if (from.length > 0) { message.setFrom(from[0]); } message.setSentDate(new Date(localMessage.mTimeStamp)); message.setUid(localMessage.mServerId); message.setFlag(Flag.DELETED, localMessage.mFlagLoaded == EmailContent.Message.FLAG_LOADED_DELETED); message.setFlag(Flag.SEEN, localMessage.mFlagRead); message.setFlag(Flag.FLAGGED, localMessage.mFlagFavorite); // message.setFlag(Flag.DRAFT, localMessage.mMailboxKey == draftMailboxKey); message.setRecipients(RecipientType.TO, Address.fromHeader(localMessage.mTo)); message.setRecipients(RecipientType.CC, Address.fromHeader(localMessage.mCc)); message.setRecipients(RecipientType.BCC, Address.fromHeader(localMessage.mBcc)); message.setReplyTo(Address.fromHeader(localMessage.mReplyTo)); message.setInternalDate(new Date(localMessage.mServerTimeStamp)); message.setMessageId(localMessage.mMessageId); message.setPriority(localMessage.mPriority);//[FEATURE]-Add-BEGIN by TCTNj.fu.zhang,04/03/2014,622697 // LocalFolder.fetch() equivalent: build body parts message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "multipart/mixed"); final MimeMultipart mp = new MimeMultipart(); mp.setSubType("mixed"); message.setBody(mp); try { addTextBodyPart(mp, "text/html", EmailContent.Body.restoreBodyHtmlWithMessageId(context, localMessage.mId)); } catch (RuntimeException rte) { LogUtils.d(Logging.LOG_TAG, "Exception while reading html body " + rte.toString()); } try { addTextBodyPart(mp, "text/plain", EmailContent.Body.restoreBodyTextWithMessageId(context, localMessage.mId)); } catch (RuntimeException rte) { LogUtils.d(Logging.LOG_TAG, "Exception while reading text body " + rte.toString()); } // Attachments final Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId); final Cursor attachments = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); try { while (attachments != null && attachments.moveToNext()) { final Attachment att = new Attachment(); att.restore(attachments); try { final InputStream content; if (att.mContentBytes != null) { // This is generally only the case for synthetic attachments, such as those // generated by unit tests or calendar invites content = new ByteArrayInputStream(att.mContentBytes); } else { String contentUriString = att.getCachedFileUri(); if (TextUtils.isEmpty(contentUriString)) { contentUriString = att.getContentUri(); } if (TextUtils.isEmpty(contentUriString)) { content = null; } else { final Uri contentUri = Uri.parse(contentUriString); content = context.getContentResolver().openInputStream(contentUri); } } final String mimeType = att.mMimeType; final Long contentSize = att.mSize; final String contentId = att.mContentId; final String filename = att.mFileName; if (content != null) { addAttachmentPart(mp, mimeType, contentSize, filename, contentId, content); } else { LogUtils.e(LogUtils.TAG, "Could not open attachment file for upsync"); } } catch (final FileNotFoundException e) { LogUtils.e(LogUtils.TAG, "File Not Found error on %s while upsyncing message", att.getCachedFileUri()); } } } finally { if (attachments != null) { attachments.close(); } } return message; }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
/** Update the UI when the OneDrive account is changed */ private void updateOnedriveAccount(Cursor cursor) { boolean haveCursor = (cursor != null); GuiUtils.setVisible(findViewById(R.id.onedrive_container), haveCursor); GuiUtils.setVisible(findViewById(R.id.onedrive_separator), haveCursor); if (haveCursor) { long id = cursor.getLong(PasswdSafeContract.Providers.PROJECTION_IDX_ID); String acct = PasswdSafeContract.Providers.getDisplayName(cursor); int freqVal = cursor.getInt(PasswdSafeContract.Providers.PROJECTION_IDX_SYNC_FREQ); ProviderSyncFreqPref freq = ProviderSyncFreqPref.freqValueOf(freqVal); itsOnedriveUri = ContentUris.withAppendedId(PasswdSafeContract.Providers.CONTENT_URI, id); Provider provider = getOnedriveProvider(); boolean authorized = provider.isAccountAuthorized(); TextView acctView = (TextView) findViewById(R.id.onedrive_acct); assert acctView != null; acctView.setText(acct);/* w ww . ja va2 s . c o m*/ GuiUtils.setVisible(findViewById(R.id.onedrive_auth_required), !authorized); View freqSpinLabel = findViewById(R.id.onedrive_interval_label); assert freqSpinLabel != null; Spinner freqSpin = (Spinner) findViewById(R.id.onedrive_interval); assert freqSpin != null; freqSpin.setSelection(freq.getDisplayIdx()); freqSpin.setEnabled(true); freqSpinLabel.setEnabled(true); } else { itsOnedriveUri = null; } }
From source file:cn.code.notes.gtask.remote.GTaskManager.java
private void refreshLocalSyncId() throws NetworkFailureException { if (mCancelled) { return;//from w w w. ja v a 2 s .c o m } // get the latest gtask list mGTaskHashMap.clear(); mGTaskListHashMap.clear(); mMetaHashMap.clear(); initGTaskList(); Cursor c = null; try { c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, "(type<>? AND parent_id<>?)", new String[] { String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER) }, NoteColumns.TYPE + " DESC"); if (c != null) { while (c.moveToNext()) { String gid = c.getString(SqlNote.GTASK_ID_COLUMN); Node node = mGTaskHashMap.get(gid); if (node != null) { mGTaskHashMap.remove(gid); ContentValues values = new ContentValues(); values.put(NoteColumns.SYNC_ID, node.getLastModified()); mContentResolver.update( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(SqlNote.ID_COLUMN)), values, null, null); } else { Log.e(TAG, "something is missed"); throw new ActionFailureException("some local items don't have gid after sync"); } } } else { Log.w(TAG, "failed to query local note to refresh sync id"); } } finally { if (c != null) { c.close(); c = null; } } }
From source file:com.example.mydemos.view.RingtonePickerActivity.java
public void onClick(View v) { Log.e("lys", "onClick called"); if (toneType == -1) { finish();/* www . ja v a 2 s . c o m*/ } Intent resultIntent = new Intent(); ContentResolver resolver = getContentResolver(); switch (v.getId()) { case R.id.ok: //if(mSelectedId >= 0 && mSelectedId != SILENT_ID && mSelectedId != DEFAULT_ID) //{ // Log.e("lys","onClick mSelectedId == "+mSelectedId); // ContentValues values = new ContentValues(2); // if(toneActivityType == ALARM_TYPE) // { // values.put(MediaStore.Audio.Media.IS_ALARM, "1"); // } // else if(toneActivityType==NOTIFICATION_TYPE) // { // values.put(MediaStore.Audio.Media.IS_NOTIFICATION, "1"); // } // else//! if(toneType==RINGTONE_TYPE) by duwenhua // { // values.put(MediaStore.Audio.Media.IS_RINGTONE, "1"); // } Log.e("lys", "onClick values == " + mSelectedUri); // resolver.update(mSelectedUri, values, null, null); // resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mSelectedUri); // setResult(RESULT_OK, resultIntent); //Toast.makeText(this, "mSelectedUri==" + mSelectedUri, // Toast.LENGTH_LONG).show(); // finish(); //} //else if(mSelectedId == SILENT_ID) //{ //resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mSelectedUri); //setResult(RESULT_OK, resultIntent); //Toast.makeText(this, "mSelectedUri==" + mSelectedUri, // Toast.LENGTH_LONG).show(); //finish(); //} if (mSelectedId == SILENT_ID) { mSelectedUri = null; } else if (mSelectedId == DEFAULT_ID) { mSelectedUri = mUriForDefaultItem; } else { Log.e("lys", "onClick values mSelectedId == " + mSelectedId); //wuqingliang modify begin20130307 for the first time entery the ringtonePickerActivity, and the ringtone is in EXTERNAL_CONTENT_URI //user click ok button in TAP ringtone. if (BaseUri != MediaStore.Audio.Media.INTERNAL_CONTENT_URI && BaseUri != MediaStore.Audio.Media.EXTERNAL_CONTENT_URI) { mSelectedUri = mExistingUri; } else { mSelectedUri = ContentUris.withAppendedId(BaseUri, mSelectedId); } //wuqingliang modify end } resultIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mSelectedUri); RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, mSelectedUri); setResult(RESULT_OK, resultIntent); //Toast.makeText(this, "mSelectedUri==" + mSelectedUri, // Toast.LENGTH_LONG).show(); finish(); break; case R.id.cancel: setResult(RESULT_CANCELED); stopMediaPlayer(); finish(); break; } }
From source file:com.fututel.ui.dialpad.DialerFragment.java
public void placeVMCall() { Long accountToUse = SipProfile.INVALID_ID; SipProfile acc = null;/*w w w. j a v a 2 s .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 == CallHandlerPlugin.getAccountIdForCallHandler(getActivity(), (new ComponentName(getActivity(), com.fututel.plugins.telephony.CallHandler.class) .flattenToString()))) { // Case gsm voice mail TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); String vmNumber = tm.getVoiceMailNumber(); if (!TextUtils.isEmpty(vmNumber)) { if (service != null) { try { service.ignoreNextOutgoingCallFor(vmNumber); } catch (RemoteException e) { Log.e(THIS_FILE, "Not possible to ignore next"); } } 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:edu.mit.mobile.android.locast.sync.SyncEngine.java
/** * Uploads any unpublished casts.//from w w w .java 2s.co m * * This is the method that does all the hard work. * * @param toSync * @param provider * @param syncMap * @param syncResult * @return the number of casts uploaded. * @throws JSONException * @throws NetworkProtocolException * @throws IOException * @throws NoPublicPath * @throws RemoteException * @throws OperationApplicationException * @throws SyncException * @throws InterruptedException */ private int uploadUnpublished(Uri toSync, Account account, ContentProviderClient provider, SyncMap syncMap, HashMap<String, SyncEngine.SyncStatus> syncStatuses, SyncResult syncResult) throws JSONException, NetworkProtocolException, IOException, NoPublicPath, RemoteException, OperationApplicationException, SyncException, InterruptedException { int count = 0; final String type = provider.getType(toSync); final boolean isDir = type.startsWith(CONTENT_TYPE_PREFIX_DIR); final Cursor uploadMe = provider.query(toSync, null, SELECTION_UNPUBLISHED, null, null); if (uploadMe == null) { throw new SyncException("could not query " + toSync); } final int idCol = uploadMe.getColumnIndex(JsonSyncableItem._ID); try { for (uploadMe.moveToFirst(); !uploadMe.isAfterLast(); uploadMe.moveToNext()) { if (Thread.interrupted()) { throw new InterruptedException(); } final long id = uploadMe.getLong(idCol); final Uri localUri = isDir ? ContentUris.withAppendedId(toSync, id) : toSync; final String postUri = MediaProvider.getPostPath(mContext, localUri); Intent intent = new Intent(SYNC_STATUS_CHANGED); intent.putExtra(EXTRA_SYNC_STATUS, "castBegin"); intent.putExtra(EXTRA_SYNC_ID, id); mContext.sendStickyBroadcast(intent); try { final JSONObject jo = JsonSyncableItem.toJSON(mContext, localUri, uploadMe, syncMap); if (DEBUG) { Log.d(TAG, "uploading " + localUri + " to " + postUri); } // Upload! Any non-successful responses are handled by // exceptions. final HttpResponse res = mNetworkClient.post(postUri, jo.toString()); long serverTime; try { serverTime = getServerTime(res); // We should never get a corrupted date from the server, // but if it does happen, // using the local time is a sane fallback. } catch (final DateParseException e) { serverTime = System.currentTimeMillis(); } // newly-created items return the JSON serialization of the // object as the server // knows it, so the local database needs to be updated to // reflect that. final JSONObject newJo = NetworkClient.toJsonObject(res); try { final SyncStatus ss = loadItemFromJsonObject(newJo, syncMap, serverTime); // update immediately, so that any cancellation or // interruption of the sync // keeps the local state in sync with what's on the // server final int updates = provider.update(localUri, ss.remoteCVs, null, null); final String locUriString = localUri.toString(); if (updates == 1) { ss.state = SyncState.NOW_UP_TO_DATE; ss.local = localUri; // ensure that it's findable by local URI too syncStatuses.put(locUriString, ss); syncMap.onPostSyncItem(mContext, account, ss.local, ss.remoteJson, true); count++; syncResult.stats.numUpdates++; } else { Log.e(TAG, "error updating " + locUriString); syncResult.stats.numSkippedEntries++; } syncResult.stats.numEntries++; } catch (final JSONException e) { if (DEBUG) { Log.e(TAG, "result was " + newJo.toString()); } throw e; } } finally { intent = new Intent(SYNC_STATUS_CHANGED); intent.putExtra(EXTRA_SYNC_STATUS, "castEnd"); intent.putExtra(EXTRA_SYNC_ID, id); mContext.sendStickyBroadcast(intent); } } } finally { uploadMe.close(); } return count; }