private void updateItemValue(long id, boolean value) { ContentValues values = new ContentValues(); values.put(MultimaniaContract.TalkEntry.IS_FAVORITE, value ? 1 : 0); AsyncQueryHandler handler = new MyScheduleAsyncQueryHandler(getActivity().getContentResolver()); handler.startUpdate( 0, null, MultimaniaContract.TalkEntry.CONTENT_URI, values, MultimaniaContract.TalkEntry._ID + "=?", new String[]{"" + id} ); if (mAccountName != null) { if (value) { ApiActions.postFavoriteTalk(getActivity(), mAccountName, id); } else { ApiActions.deleteFavoriteTalk(getActivity(), mAccountName, id); } } }
private void updateItemValue(long id, boolean value) { ContentValues values = new ContentValues(); values.put(MultimaniaContract.TalkEntry.IS_FAVORITE, value ? 1 : 0); AsyncQueryHandler handler = new SuggestionAsyncQueryHandler(getActivity().getContentResolver()); handler.startUpdate( 0, null, MultimaniaContract.TalkEntry.CONTENT_URI, values, MultimaniaContract.TalkEntry._ID + "=?", new String[]{"" + id} ); if (mAccountName != null) { if (value) { ApiActions.postFavoriteTalk(getActivity(), mAccountName, id); } else { ApiActions.deleteFavoriteTalk(getActivity(), mAccountName, id); } } }
/** * Check for locked messages in all threads or a specified thread. * * @param handler An AsyncQueryHandler that will receive onQueryComplete * upon completion of looking for locked messages * @param threadIds A list of threads to search. null means all threads * @param token The token that will be passed to onQueryComplete */ public static void startQueryHaveLockedMessages(AsyncQueryHandler handler, Collection<Long> threadIds, int token) { handler.cancelOperation(token); Uri uri = MmsSms.CONTENT_LOCKED_URI; String selection = null; if (threadIds != null) { StringBuilder buf = new StringBuilder(); int i = 0; for (long threadId : threadIds) { if (i++ > 0) { buf.append(" OR "); } // We have to build the selection arg into the selection because deep down in // provider, the function buildUnionSubQuery takes selectionArgs, but ignores it. buf.append(Mms.THREAD_ID).append("=").append(Long.toString(threadId)); } selection = buf.toString(); } handler.startQuery(token, threadIds, uri, ALL_THREADS_PROJECTION, selection, null, Conversations.DEFAULT_SORT_ORDER); }
public static void savePayment(Payment payment, final Handler handler) { final ContentValues values = getContentValuesFromPaymentInstance(payment); AsyncQueryHandler insertPaymentHandler = new AsyncQueryHandler(mContentResolver) { @Override protected void onInsertComplete(int token, Object cookie, Uri uri) { if (handler != null) { Message message = Message.obtain(); message.what = MESSAGE_WHAT_SAVED_PAYMENT_URL; message.obj = uri; handler.sendMessage(message); } } }; insertPaymentHandler.startInsert(0, null, paymentsUri, values); }
/** * retrieve a Bill Object from DB and return it by using Handler to send a Message * * @param id * @param handler */ public static void getBill(long id, final Handler handler) { Uri uri = BillContract.Bills.buildBillUri(String.valueOf(id)); // Cursor cursor = mContentResolver.query(uri, projection, null, null, null); new AsyncQueryHandler(mContentResolver) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (handler != null && cursor != null) { Bill bill = getBillFromCursor(cursor); Message message = Message.obtain(); message.what = MESSAGE_WHAT_GET_BILL; message.obj = bill; handler.sendMessage(message); } } }.startQuery(0, null, uri, projection, null, null, null); }
public static void savePaymentInfo(PaymentInfo paymentInfo, final Handler handler) { final ContentValues values = getContentValuesFromPaymentInfoInstance(paymentInfo); AsyncQueryHandler insertPaymentInfoHandler = new AsyncQueryHandler(mContentResolver) { @Override protected void onInsertComplete(int token, Object cookie, Uri uri) { if (handler != null) { Message message = Message.obtain(); message.what = MESSAGE_WHAT_SAVED_PAYMENTINFO_URL; message.obj = uri; handler.sendMessage(message); } } }; insertPaymentInfoHandler.startInsert(0, null, paymentInfosUri, values); }
@Override protected void onStop() { //TODO: Archive of our own & FictionPress if (mData != null && mData.isInLibrary()) { ContentResolver resolver = getContentResolver(); AsyncQueryHandler handler = new AsyncQueryHandler(resolver){}; int offset = getOffset(); ContentValues values = new ContentValues(1); values.put(SqlConstants.KEY_LAST, mCurrentPage); values.put(SqlConstants.KEY_OFFSET, offset); values.put(SqlConstants.KEY_LAST_READ, System.currentTimeMillis()); handler.startUpdate(0, null, StoryProvider.FF_CONTENT_URI, values, SqlConstants.KEY_STORY_ID + " = ?", new String[] { String.valueOf(mStoryId) }); SharedPreferences preference = getSharedPreferences(MainActivity.EXTRA_PREF,MODE_PRIVATE); SharedPreferences.Editor editor = preference.edit(); editor.putLong(MainActivity.EXTRA_RESUME_ID, mStoryId); editor.commit(); } super.onStop(); }
public static void addFavorite(Context context, Movie movie) { Log.d(TAG, "Inserting favorite: " + movie.getTitle()); ContentValues values = new ContentValues(); values.put(MovieContract.MovieEntry.COLUMN_MOVIE_ID, movie.getId()); values.put(MovieContract.MovieEntry.COLUMN_TITLE, movie.getTitle()); values.put(MovieContract.MovieEntry.COLUMN_ORIGINAL_TITLE, movie.getOriginalTitle()); values.put(MovieContract.MovieEntry.COLUMN_RELEASE_DATE, movie.getReleaseDate()); values.put(MovieContract.MovieEntry.COLUMN_OVERVIEW, movie.getOverview()); values.put(MovieContract.MovieEntry.COLUMN_VOTE_AVERAGE, movie.getVoteAverage()); values.put(MovieContract.MovieEntry.COLUMN_VOTE_COUNT, movie.getVoteCount()); values.put(MovieContract.MovieEntry.COLUMN_POSTER_PATH, movie.getPosterPath()); values.put(MovieContract.MovieEntry.COLUMN_BACKDROP_PATH, movie.getBackdropPath()); values.put(MovieContract.MovieEntry.COLUMN_POPULARITY, movie.getPopularity()); values.put(MovieContract.MovieEntry.COLUMN_FAVORITE, 1); values.put(MovieContract.MovieEntry.COLUMN_LANGUAGE, movie.getOriginalLanguage()); values.put(MovieContract.MovieEntry.COLUMN_VIDEO, movie.isVideo()); values.put(MovieContract.MovieEntry.COLUMN_ADULT, movie.isAdult()); final AsyncQueryHandler handler = new AsyncCrudHandler(context.getContentResolver()); handler.startInsert(2, null, MovieContract.MovieEntry.CONTENT_URI, values); // update genres insertGenres(context, movie.getId(), movie.getGenreIds()); }
/** * Queries the defined projection, selection and sort order on a background thread * on the given URI through the ContentResolver retrieved from the given context.<br /> * <br /> * The callback is called on the thread that called this method when the query finishes. * @param context * @param uri * @param callback */ public void queryAsync( Context context, Uri uri, final AsyncQueryCallback callback ) { validateForQuery(); AsyncQueryHandler aqh = new AsyncQueryHandler( context.getContentResolver() ) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { callback.queryCompleted(cursor); if ( !cursor.isClosed() ) { cursor.close(); } } }; Pair<String, String[]> builtSelection = buildSelection(); aqh.startQuery(0, null, uri, projection, builtSelection.first, builtSelection.second, sortOrder ); }
public void setReservationStatus(Uri sessionUri, @ScheduleContract.MyReservations.ReservationStatus int reservationStatus, String title) { LOGD(TAG, "setReservationStatus session uri=" + sessionUri + " reservationStatus=" + reservationStatus + " title=" + title); String accountName = AccountUtils.getActiveAccountName(mContext); String sessionId = ScheduleContract.Sessions.getSessionId(sessionUri); Uri myReservationsUri = ScheduleContract.MyReservations.buildMyReservationUri(accountName); @SuppressLint("HandlerLeak") // this is short-lived AsyncQueryHandler handler = new AsyncQueryHandler(mContext.getContentResolver()) { }; final ContentValues values = new ContentValues(); values.put(ScheduleContract.MyReservations.SESSION_ID, sessionId); values.put(ScheduleContract.MyReservations.MY_RESERVATION_STATUS, reservationStatus); values.put(ScheduleContract.MyReservations.MY_RESERVATION_ACCOUNT_NAME, accountName); int offset = SyncUtils.getServerTimeOffset(mContext); values.put(ScheduleContract.MyReservations.MY_RESERVATION_TIMESTAMP, System.currentTimeMillis() + offset); handler.startInsert(-1, null, myReservationsUri, values); }
@Override public void onInfoWindowClick(Marker marker) { new IsFavAsyncQuery(mContext.getContentResolver(), marker) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { cursor.moveToFirst(); final boolean isFav = !(cursor.getInt(cursor.getColumnIndex(StopTable.IS_FAV)) == 1); if (isFav) { Toast.makeText(mContext, mContext.getString(R.string.fav_added), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mContext, mContext.getString(R.string.fav_removed), Toast.LENGTH_SHORT).show(); } cursor.close(); final ContentValues contentValues = new ContentValues(1); contentValues.put(StopTable.IS_FAV, isFav); new AsyncQueryHandler(mContext.getContentResolver()) { } .startUpdate(0, null, StopsProvider.CONTENT_URI, contentValues, StopTable.NAME_COL + "=?", new String[]{mMarker.getTitle()}); } }.performQuery(); }
private Cursor getQueryCursor(AsyncQueryHandler async, String filter) { if (filter == null) { filter = ""; } String[] ccols = new String[] { BaseColumns._ID, Audio.Media.MIME_TYPE, Audio.Artists.ARTIST, Audio.Albums.ALBUM, Audio.Media.TITLE, "data1", "data2" }; Uri search = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(filter)); Cursor ret = null; if (async != null) { async.startQuery(0, null, search, ccols, null, null, null); } else { ret = MusicUtils.query(this, search, ccols, null, null, null); } return ret; }
public NumberLocate(final Context mContext, final Handler handler){ this.mContext = mContext; this.handler = handler; queryHandler = new AsyncQueryHandler(mContext.getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor != null && cursor.moveToNext()) { String city = cursor.getString(0); cursor.close(); Message msg = new Message(); msg.obj = city; handler.sendMessage(msg); PhoneStatusRecevier.saveAsCache(mContext,number,city); } } }; }
private Cursor getQueryCursor(AsyncQueryHandler async, String filter) { if (filter == null) { filter = ""; } String[] ccols = new String[] { BaseColumns._ID, // this will be the artist, album or track ID MediaStore.Audio.Media.MIME_TYPE, // mimetype of audio file, or "artist" or "album" MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Media.TITLE, "data1", "data2" }; Uri search = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(filter)); Cursor ret = null; if (async != null) { async.startQuery(0, null, search, ccols, null, null, null); } else { ret = MusicUtils.query(this, search, ccols, null, null, null); } return ret; }
private Cursor getArtistCursor(AsyncQueryHandler async, String filter) { String[] cols = new String[] { MediaStore.Audio.Artists._ID, MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Artists.NUMBER_OF_ALBUMS, MediaStore.Audio.Artists.NUMBER_OF_TRACKS }; Uri uri = MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI; if (!TextUtils.isEmpty(filter)) { uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filter)).build(); } Cursor ret = null; if (async != null) { async.startQuery(0, null, uri, cols, null , null, MediaStore.Audio.Artists.ARTIST_KEY); } else { ret = MusicUtils.query(this, uri, cols, null , null, MediaStore.Audio.Artists.ARTIST_KEY); } return ret; }
public void favoritePressed(View button) { ContentValues cv = new ContentValues(); cv.put(Feeds.TITLE, name + " (RSS)"); cv.put(Feeds.SHORTTITLE, name); cv.put(Feeds.URL, query); cv.put(Feeds.UNREAD, -2); cv.put(Feeds.COUNT, -2); cv.put(Feeds.LAST_UPDATE, 0); new AsyncQueryHandler(this.getContentResolver()) { @Override protected void onInsertComplete(int id, Object cookie, Uri uri) { Toast.makeText(getBaseContext(), id, Toast.LENGTH_SHORT).show(); } }.startInsert(R.string.added_to_favorites_rss, null, Feeds.CONTENT_URI, cv); favorite = true; /*supportInvalidateOptionsMenu();*/ }
public void addFavorite() { ContentValues cv = new ContentValues(); cv.put(Feeds.TITLE, name); cv.put(Feeds.SHORTTITLE, query); cv.put(Feeds.URL, url); cv.put(Feeds.UNREAD, -1); cv.put(Feeds.COUNT, -1); cv.put(Feeds.LAST_UPDATE, 0); new AsyncQueryHandler(this.getContentResolver()) { @Override protected void onInsertComplete(int id, Object cookie, Uri uri) { Toast.makeText(getBaseContext(), id, Toast.LENGTH_SHORT).show(); } }.startInsert(R.string.added_to_favorites, null, Feeds.CONTENT_URI, cv); favorite = true; supportInvalidateOptionsMenu(); }
/** * Check for locked messages in all threads or a specified thread. * @param handler An AsyncQueryHandler that will receive onQueryComplete * upon completion of looking for locked messages * @param threadIds A list of threads to search. null means all threads * @param token The token that will be passed to onQueryComplete */ public static void startQueryHaveLockedMessages(AsyncQueryHandler handler, Collection<Long> threadIds, int token) { handler.cancelOperation(token); Uri uri = MmsSms.CONTENT_LOCKED_URI; String selection = null; if (threadIds != null) { StringBuilder buf = new StringBuilder(); int i = 0; for (long threadId : threadIds) { if (i++ > 0) { buf.append(" OR "); } // We have to build the selection arg into the selection because deep down in // provider, the function buildUnionSubQuery takes selectionArgs, but ignores it. buf.append(Mms.THREAD_ID).append("=").append(Long.toString(threadId)); } selection = buf.toString(); } handler.startQuery(token, threadIds, uri, ALL_THREADS_PROJECTION, selection, null, Conversations.DEFAULT_SORT_ORDER); }
public void setSessionStarred(Uri sessionUri, boolean starred, String title) { LOGD(TAG, "setSessionStarred uri=" + sessionUri + " starred=" + starred + " title=" + title); sessionUri = ScheduleContract.addCallerIsSyncAdapterParameter(sessionUri); final ContentValues values = new ContentValues(); values.put(ScheduleContract.Sessions.SESSION_STARRED, starred); AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolver()) { }; handler.startUpdate(-1, null, sessionUri, values, null, null); EasyTracker.getTracker().sendEvent( "Session", starred ? "Starred" : "Unstarred", title, 0L); // Because change listener is set to null during initialization, these // won't fire on pageview. mActivity.sendBroadcast(ScheduleWidgetProvider.getRefreshBroadcastIntent(mActivity, false)); // Sync to the cloudz. uploadStarredSession(mActivity, sessionUri, starred); }
@Override public boolean requestModelUpdate(UserActionEnum action, @Nullable Bundle args) { // If the action is a VIDEO_VIEWED we save the information that the video has been viewed by // the user in AppData. if (action.equals(VideoLibraryUserActionEnum.VIDEO_PLAYED)) { if (args != null && args.containsKey(KEY_VIDEO_ID)) { String playedVideoId = args.getString(KEY_VIDEO_ID); LOGD(TAG, "setVideoViewed id=" + playedVideoId); Uri myPlayedVideoUri = ScheduleContract.MyViewedVideos.buildMyViewedVideosUri( AccountUtils.getActiveAccountName(mActivity)); AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolver()) {}; final ContentValues values = new ContentValues(); values.put(ScheduleContract.MyViewedVideos.VIDEO_ID, playedVideoId); handler.startInsert(-1, null, myPlayedVideoUri, values); // Because change listener is set to null during initialization, these // won't fire on pageview. mActivity.sendBroadcast(ScheduleWidgetProvider.getRefreshBroadcastIntent(mActivity, false)); // Request an immediate user data sync to reflect the viewed video in the cloud. SyncHelper.requestManualSync(AccountUtils.getActiveAccount(mActivity), true); } else { LOGE(TAG, "The VideoLibraryUserActionEnum.VIDEO_VIEWED action was called without a " + "proper Bundle."); return false; } } return true; }
public void setSessionStarred(Uri sessionUri, boolean starred, String title) { LOGD(TAG, "setSessionStarred uri=" + sessionUri + " starred=" + starred + " title=" + title); String sessionId = ScheduleContract.Sessions.getSessionId(sessionUri); Uri myScheduleUri = ScheduleContract.MySchedule.buildMyScheduleUri( AccountUtils.getActiveAccountName(mActivity)); AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolver()) { }; final ContentValues values = new ContentValues(); values.put(ScheduleContract.MySchedule.SESSION_ID, sessionId); values.put(ScheduleContract.MySchedule.MY_SCHEDULE_IN_SCHEDULE, starred?1:0); handler.startInsert(-1, null, myScheduleUri, values); // ANALYTICS EVENT: Add or remove a session from the schedule // Contains: Session title, whether it was added or removed (starred or unstarred) AnalyticsHelper.sendEvent( "Session", starred ? "Starred" : "Unstarred", title); // Because change listener is set to null during initialization, these // won't fire on pageview. mActivity.sendBroadcast(ScheduleWidgetProvider.getRefreshBroadcastIntent(mActivity, false)); // Request an immediate user data sync to reflect the starred user sessions in the cloud SyncHelper.requestManualSync(AccountUtils.getActiveAccount(mActivity), true); }
public static Cursor getPlaylistCursor(AsyncQueryHandler async, String filterstring, Context context) { StringBuilder where = new StringBuilder(); where.append(MediaStore.Audio.Playlists.NAME + " != ''"); // Add in the filtering constraints String[] keywords = null; if (filterstring != null) { String[] searchWords = filterstring.split(" "); keywords = new String[searchWords.length]; Collator col = Collator.getInstance(); col.setStrength(Collator.PRIMARY); for (int i = 0; i < searchWords.length; i++) { keywords[i] = '%' + searchWords[i] + '%'; } for (int i = 0; i < searchWords.length; i++) { where.append(" AND "); where.append(MediaStore.Audio.Playlists.NAME + " LIKE ?"); } } String whereclause = where.toString(); if (async != null) { async.startQuery(0, null, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols, whereclause, keywords, MediaStore.Audio.Playlists.NAME); return null; } Cursor c; c = MusicUtils.query(context, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols, whereclause, keywords, MediaStore.Audio.Playlists.NAME); return filterCursor(c); }
public static void queryAllArtists(AsyncQueryHandler queryHandler, int max) { String sortOrder = MusicStore.Audio.Artists.DEFAULT_SORT_ORDER + LIMIT + max; StringBuilder where = new StringBuilder(); where.append(MusicStore.Audio.Artists.ARTIST).append(" != ''"); queryHandler.startQuery( 0, null, MusicStore.Audio.Artists.EXTERNAL_RW_CONTENT_URI, ARTIST_COLS, where.toString(), null, sortOrder); }
/** * 初始化数据 */ public void initialData() { new AsyncQueryHandler(getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { list = new ArrayList<>(); while (cursor.moveToNext()) { String main = cursor.getString(cursor.getColumnIndex("main")); String user = cursor.getString(cursor.getColumnIndex("user")); String nickname = cursor.getString(cursor.getColumnIndex("nickname")); String icon = cursor.getString(cursor.getColumnIndex("icon")); int type = cursor.getInt(cursor.getColumnIndex("type")); String content = cursor.getString(cursor.getColumnIndex("content")); String sex = cursor.getString(cursor.getColumnIndex("sex")); String too = cursor.getString(cursor.getColumnIndex("too")); String times = cursor.getString(cursor.getColumnIndex("time")); long time = Long.parseLong(times); int viewType = cursor.getInt(cursor.getColumnIndex("viewtype")); XmppChat xm = new XmppChat(main, user, nickname, icon, type, content, sex, too, viewType, time); Log.i("chat》》》》》》》》》》》", too + "\n" + user.toLowerCase()); list.add(xm); } adapter = new ChatAdapter(); msgListView.setAdapter(adapter); msgListView.setSelection(adapter.getCount() - 1); } }.startQuery(0, null, XmppFriendMessageProvider.CONTENT_CHATS_URI, null, "main=?", new String[]{user.getUser() + xf.getUser().getUser()}, null); }
private void injectLayout() { // for panel mSlidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout); mEmotions = (GridView) findViewById(R.id.emotions); mEmotions.setAdapter(new EmotionsAdapter(this)); mEmotions.setOnItemClickListener(this); mSlidingPaneLayout.setPanelSlideListener(new SliderListener()); mSlidingPaneLayout.openPane(); mSlidingPaneLayout.getViewTreeObserver().addOnGlobalLayoutListener(new FirstLayoutListener()); // for tweet mAvatar = (ImageView) findViewById(R.id.avatar); mScreenName = (TextView) findViewById(R.id.screen_name); mText = (EditText) findViewById(R.id.text); mLocationMarker = findViewById(R.id.location_marker); // set data to layout... new AsyncQueryHandler(getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.moveToNext()) { Picasso.with(ComposeTweetActivity.this) .load(cursor.getString(cursor.getColumnIndex(User.avatar_large))) .placeholder(R.drawable.error) .error(R.drawable.error) .into(mAvatar); mScreenName.setText("@" + cursor.getString(cursor.getColumnIndex(User.screen_name))); } cursor.close(); } }.startQuery(0, null, CatnutProvider.parse(User.MULTIPLE, mApp.getAccessToken().uid), new String[]{User.avatar_large, User.screen_name}, null, null, null); // other stuffs... mText.addTextChangedListener(this); }
public void updateEntityInAsync(final ContentResolver contentResolver, ContentValues content) { final int DUMMY_TOKEN = -1; AsyncQueryHandler handler = new AsyncQueryHandler(contentResolver) { @Override protected void onUpdateComplete(int token, Object cookie, int result) { super.onUpdateComplete(token, cookie, result); } }; // We are using a "LIKE" to compare the ID because it's a string handler.startUpdate(DUMMY_TOKEN, null, this.getProviderUri(), content, DB.ID + " LIKE ?", new String[]{this.id}); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()){ case R.id.action_favorite:{ mIsFavorite=!mIsFavorite; ContentValues values = new ContentValues(); values.put(MultimaniaContract.TalkEntry.IS_FAVORITE,mIsFavorite); AsyncQueryHandler handler = new TalkAsyncQueryHandler(getActivity().getContentResolver()); handler.startUpdate( 0, null, MultimaniaContract.TalkEntry.CONTENT_URI, values, MultimaniaContract.TalkEntry._ID+"=?", new String[]{""+ mTalkId} ); if(mAccountName!=null){ ApiActions.postFavoriteTalk(getActivity(), mAccountName, mTalkId); } setActionIcon(); break; } case R.id.action_share: { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.imattending) + mTitle + " @multimania. " + getString(R.string.readmoreatmm)+ ". " + getString(R.string.hashtag_mm)); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share_with))); } } return super.onOptionsItemSelected(item); }
/** * Start a query for all conversations in the database on the specified * AsyncQueryHandler. * * @param handler An AsyncQueryHandler that will receive onQueryComplete * upon completion of the query * @param token The token that will be passed to onQueryComplete */ public static void startQueryForAll(AsyncQueryHandler handler, int token) { handler.cancelOperation(token); // This query looks like this in the log: // I/Database( 147): elapsedTime4Sql|/data/data/com.android.providers.telephony/databases/ // mmssms.db|2.253 ms|SELECT _id, date, message_count, recipient_ids, snippet, snippet_cs, // read, error, has_attachment FROM threads ORDER BY date DESC startQuery(handler, token, null); }
/** * Start a query for in the database on the specified AsyncQueryHandler with the specified * "where" clause. * * @param handler An AsyncQueryHandler that will receive onQueryComplete * upon completion of the query * @param token The token that will be passed to onQueryComplete * @param selection A where clause (can be null) to select particular conv items. */ public static void startQuery(AsyncQueryHandler handler, int token, String selection) { handler.cancelOperation(token); // This query looks like this in the log: // I/Database( 147): elapsedTime4Sql|/data/data/com.android.providers.telephony/databases/ // mmssms.db|2.253 ms|SELECT _id, date, message_count, recipient_ids, snippet, snippet_cs, // read, error, has_attachment FROM threads ORDER BY date DESC handler.startQuery(token, null, sAllThreadsUri, ALL_THREADS_PROJECTION, selection, null, Conversations.DEFAULT_SORT_ORDER); }
/** * Check for locked messages in all threads or a specified thread. * * @param handler An AsyncQueryHandler that will receive onQueryComplete * upon completion of looking for locked messages * @param threadId The threadId of the thread to search. -1 means all threads * @param token The token that will be passed to onQueryComplete */ public static void startQueryHaveLockedMessages(AsyncQueryHandler handler, long threadId, int token) { ArrayList<Long> threadIds = null; if (threadId != -1) { threadIds = new ArrayList<Long>(); threadIds.add(threadId); } startQueryHaveLockedMessages(handler, threadIds, token); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPrefs = mContext.getPrefs(); mRes = mContext.getResources(); // When the query completes cons up a new adapter and set our list adapter to that. mQueryHandler = new AsyncQueryHandler(mContext.getContentResolver()) { protected void onQueryComplete(int token, Object cookie, Cursor c) { mAdapter.changeCursor(c); mAdapter.setQuery(mSearchString); } }; }
public static void saveBill(final Bill bill, final Handler handler) { long id = bill.getId(); final ContentValues values = getContentValuesFromBillInstance(bill); if (id >= 0) { // this is an update final Uri billUriWithId = BillContract.Bills.buildBillUri(String.valueOf(id)); new AsyncQueryHandler(mContentResolver) { }.startUpdate(0, null, billUriWithId, values, null, null); return; } AsyncQueryHandler insertBillHandler = new AsyncQueryHandler(mContentResolver) { @Override protected void onInsertComplete(int token, Object cookie, Uri uri) { if (handler != null) { Message message = Message.obtain(); message.what = MESSAGE_WHAT_SAVED_BILL_URL; message.obj = uri; handler.sendMessage(message); } } }; insertBillHandler.startInsert(0, null, billsUri, values); }