Example usage for android.content AsyncQueryHandler AsyncQueryHandler

List of usage examples for android.content AsyncQueryHandler AsyncQueryHandler

Introduction

In this page you can find the example usage for android.content AsyncQueryHandler AsyncQueryHandler.

Prototype

public AsyncQueryHandler(ContentResolver cr) 

Source Link

Usage

From source file:org.mozilla.search.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_activity_main);

    queryHandler = new AsyncQueryHandler(getContentResolver()) {
    };/*from  w ww.  j  ava  2s  .  c om*/

    editText = (ClearableEditText) findViewById(R.id.search_edit_text);
    editText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setEditState(EditState.EDITING);
        }
    });

    editText.setTextListener(new ClearableEditText.TextListener() {
        @Override
        public void onChange(String text) {
            // Only load suggestions if we're in edit mode.
            if (editState == EditState.EDITING) {
                suggestionsFragment.loadSuggestions(text);
            }
        }

        @Override
        public void onSubmit(String text) {
            // Don't submit an empty query.
            final String trimmedQuery = text.trim();
            if (!TextUtils.isEmpty(trimmedQuery)) {
                onSearch(trimmedQuery);
            }
        }

        @Override
        public void onFocusChange(boolean hasFocus) {
            setEditState(hasFocus ? EditState.EDITING : EditState.WAITING);
        }
    });

    preSearch = findViewById(R.id.presearch);
    postSearch = findViewById(R.id.postsearch);

    suggestions = findViewById(R.id.suggestions);
    suggestionsFragment = (SuggestionsFragment) getSupportFragmentManager().findFragmentById(R.id.suggestions);

    animationText = (TextView) findViewById(R.id.animation_text);
    animationCard = findViewById(R.id.animation_card);

    cardPaddingX = getResources().getDimensionPixelSize(R.dimen.card_background_padding_x);
    cardPaddingY = getResources().getDimensionPixelSize(R.dimen.card_background_padding_y);
    textEndY = getResources().getDimensionPixelSize(R.dimen.animation_text_translation_y);

    if (savedInstanceState != null) {
        setSearchState(SearchState.valueOf(savedInstanceState.getString(KEY_SEARCH_STATE)));
        setEditState(EditState.valueOf(savedInstanceState.getString(KEY_EDIT_STATE)));

        final String query = savedInstanceState.getString(KEY_QUERY);
        editText.setText(query);

        // If we're in the postsearch state, we need to re-do the query.
        if (searchState == SearchState.POSTSEARCH) {
            ((PostSearchFragment) getSupportFragmentManager().findFragmentById(R.id.postsearch))
                    .startSearch(query);
        }
    } else {
        // If there isn't a state to restore, the activity will start in the presearch state,
        // and we should enter editing mode to bring up the keyboard.
        setEditState(EditState.EDITING);
    }
}

From source file:xyz.template.material.menu.utils.SessionsHelper.java

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(mActivity);

    AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolver()) {
    };//from   w ww . j ava 2  s.  c  om
    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]
     * TRIGGER:   Add or remove a session from the schedule.
     * CATEGORY:  'Session'
     * ACTION:    'Starred' or 'Unstarred'
     * LABEL:     session title/subtitle
     * [/ANALYTICS]
     */
    //        AnalyticsManager.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));

    // Request an immediate user data sync to reflect the starred user sessions in the cloud
    //        SyncHelper.requestManualSync(AccountUtils.getActiveAccount(mActivity), true);

}

From source file:org.jamienicol.episodes.EpisodeDetailsFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.episode_details_fragment, container, false);

    rootView = view.findViewById(R.id.root);
    titleView = (TextView) view.findViewById(R.id.title);
    overviewView = (TextView) view.findViewById(R.id.overview);
    dateView = (TextView) view.findViewById(R.id.date);
    watchedCheckBox = (CheckBox) view.findViewById(R.id.watched);
    watchedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            final ContentResolver contentResolver = getActivity().getContentResolver();
            final AsyncQueryHandler handler = new AsyncQueryHandler(contentResolver) {
            };//w w w.j  ava 2 s .c om

            final Uri episodeUri = Uri.withAppendedPath(ShowsProvider.CONTENT_URI_EPISODES,
                    String.valueOf(episodeId));

            final ContentValues episodeValues = new ContentValues();
            episodeValues.put(EpisodesTable.COLUMN_WATCHED, isChecked);

            handler.startUpdate(0, null, episodeUri, episodeValues, null, null);
        }
    });

    return view;
}

From source file:com.github.longkai.zhihu.ui.AnswerActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.answer);/*from w ww .  j a  va2  s.  c o m*/

    final TextView title = (TextView) findViewById(android.R.id.title);
    final WebView desc = (WebView) findViewById(R.id.description);
    final TextView nick = (TextView) findViewById(R.id.nick);
    final ImageView avatar = (ImageView) findViewById(R.id.avatar);
    final TextView status = (TextView) findViewById(R.id.status);
    final WebView answer = (WebView) findViewById(R.id.content);
    final TextView last_alter_date = (TextView) findViewById(R.id.last_alter_date);

    id = getIntent().getLongExtra(ANSWER_ID, 0);
    new AsyncQueryHandler(getContentResolver()) {
        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            if (cursor.moveToNext()) {
                // 
                aid = cursor.getLong(cursor.getColumnIndex(ANSWER_ID));
                qid = cursor.getLong(cursor.getColumnIndex(QUESTION_ID));
                questionTitle = cursor.getString(cursor.getColumnIndex(TITLE));
                title.setText(questionTitle);
                String description = cursor.getString(cursor.getColumnIndex(DESCRIPTION));
                if (TextUtils.isEmpty(description)) {
                    desc.setVisibility(View.GONE);
                } else {
                    desc.loadDataWithBaseURL(null, description, "text/html", "utf-8", null);
                    desc.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                    desc.setBackgroundColor(getResources().getColor(R.color.bgcolor));
                }

                // 
                uid = cursor.getString(cursor.getColumnIndex(UID));
                nick.setText(cursor.getString(cursor.getColumnIndex(NICK)));
                String src = cursor.getString(cursor.getColumnIndex(AVATAR));
                ZhihuApp.getImageLoader().get(src,
                        ImageLoader.getImageListener(avatar, R.drawable.ic_launcher, R.drawable.ic_launcher));
                status.setText(cursor.getString(cursor.getColumnIndex(STATUS)));

                // 
                String content = cursor.getString(cursor.getColumnIndex(ANSWER));
                answerDigest = content.length() > 50 ? content.substring(0, 50) : content;
                answer.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
                answer.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                answer.setBackgroundColor(getResources().getColor(R.color.bgcolor));

                last_alter_date.setText(DateUtils
                        .getRelativeTimeSpanString(cursor.getLong(cursor.getColumnIndex(LAST_ALTER_DATE))));

                cursor.close();
            }
        }
    }.startQuery(0, null, Uri.parse(ZhihuProvider.BASE_URI + Constants.ITEMS + "/" + id), ITEM_PROJECTION, null,
            null, null);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

From source file:com.razza.apps.iosched.util.SessionsHelper.java

public void setSessionStarred(Uri sessionUri, boolean starred, String title) {
    LogUtils.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()) {
    };/*from w w  w.  j av a2 s .com*/
    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);
}

From source file:com.google.samples.apps.iosched.util.SessionsHelper.java

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()) {
    };/*from   w  w  w  . j a  va 2 s . c o m*/
    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);
}

From source file:org.jamienicol.episodes.NextEpisodeFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.episode_details_fragment, container, false);

    rootView = view.findViewById(R.id.root);
    titleView = (TextView) view.findViewById(R.id.title);
    overviewView = (TextView) view.findViewById(R.id.overview);
    dateView = (TextView) view.findViewById(R.id.date);
    watchedCheckBox = (CheckBox) view.findViewById(R.id.watched);
    watchedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // Make sure we have a next episode
            if (episodeId == -1) {
                Log.w(TAG, "Watched check changed but there is no next episode.");
                return;
            }//w w  w  .j  a  v  a 2 s. c om

            final ContentResolver contentResolver = getActivity().getContentResolver();
            final AsyncQueryHandler handler = new AsyncQueryHandler(contentResolver) {
            };

            final Uri episodeUri = Uri.withAppendedPath(ShowsProvider.CONTENT_URI_EPISODES,
                    String.valueOf(episodeId));

            final ContentValues episodeValues = new ContentValues();
            episodeValues.put(EpisodesTable.COLUMN_WATCHED, isChecked);

            handler.startUpdate(0, null, episodeUri, episodeValues, null, null);
        }
    });

    return view;
}

From source file:com.kku.apps.pricesearch.util.Utils.java

public static void deleteFavorites(Context context, ListItem item) {
    final AsyncQueryHandler dbHandler = new AsyncQueryHandler(context.getContentResolver()) {
    };//from w w w.j  a v a2s  . c  om
    dbHandler.startDelete(0, null, SearchContract.URI_FAVORITES, FavoritesColumns.ITEMURL + " = ?",
            new String[] { item.getItemUrl() });
}

From source file:com.google.samples.apps.sergio.util.SessionsHelper.java

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(mActivity);

    AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolver()) {
    };//from www  .  j a  v  a2  s .c o m
    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]
     * TRIGGER:   Add or remove a session from the schedule.
     * CATEGORY:  'Session'
     * ACTION:    'Starred' or 'Unstarred'
     * LABEL:     session title/subtitle
     * [/ANALYTICS]
     */
    AnalyticsManager.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));

    // Request an immediate user data sync to reflect the starred user sessions in the cloud
    SyncHelper.requestManualSync(AccountUtils.getActiveAccount(mActivity), true);

}

From source file:com.saarang.samples.apps.iosched.util.SessionsHelper.java

public void setSessionStarred(Uri sessionUri, boolean starred, String title) {
    LogUtils.LOGD(TAG, "setSessionStarred uri=" + sessionUri + " starred=" + starred + " title=" + title);
    String sessionId = ScheduleContract.Sessions.getSessionId(sessionUri);
    Uri myScheduleUri = ScheduleContract.MySchedule.buildMyScheduleUri(mActivity);

    AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolver()) {
    };// w ww .java2 s  .co m
    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]
     * TRIGGER:   Add or remove a session from the schedule.
     * CATEGORY:  'Session'
     * ACTION:    'Starred' or 'Unstarred'
     * LABEL:     session title/subtitle
     * [/ANALYTICS]
     */
    AnalyticsManager.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));

    // Request an immediate user data sync to reflect the starred user sessions in the cloud
    SyncHelper.requestManualSync(AccountUtils.getActiveAccount(mActivity), true);

}