Example usage for android.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER

List of usage examples for android.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER

Introduction

In this page you can find the example usage for android.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER.

Prototype

int FLAG_REGISTER_CONTENT_OBSERVER

To view the source code for android.widget CursorAdapter FLAG_REGISTER_CONTENT_OBSERVER.

Click Source Link

Document

If set the adapter will register a content observer on the cursor and will call #onContentChanged() when a notification comes in.

Usage

From source file:io.fabric.samples.cannonball.activity.PoemHistoryActivity.java

private void setUpPoemList() {
    shareListener = new OnShareClickListener();
    deleteListener = new OnDeleteClickListener();

    final ListView poemsList = (ListView) findViewById(R.id.poem_history_list);

    adapter = new PoemCursorAdapter(getApplicationContext(), null,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    // MoPub integration
    final ViewBinder mopubViewBinder = new ViewBinder.Builder(R.layout.native_ad_layout)
            .mainImageId(R.id.native_ad_main_image).iconImageId(R.id.native_ad_icon_image)
            .titleId(R.id.native_ad_title).textId(R.id.native_ad_text).build();

    final MoPubNativeAdRenderer adRenderer = new MoPubNativeAdRenderer(mopubViewBinder);
    moPubAdAdapter = new MoPubAdAdapter(this, adapter);
    moPubAdAdapter.registerAdRenderer(adRenderer);

    poemsList.setAdapter(moPubAdAdapter);
}

From source file:galilei.kelimekavanozu.activity.PoemHistoryActivity.java

private void setUpPoemList() {
    shareListener = new OnShareClickListener();
    deleteListener = new OnDeleteClickListener();

    final ListView poemsList = (ListView) findViewById(R.id.poem_history_list);

    adapter = new PoemCursorAdapter(getApplicationContext(), null,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    // MoPub integration
    final ViewBinder mopubViewBinder = new ViewBinder.Builder(R.layout.native_ad_layout)
            .mainImageId(R.id.native_ad_main_image).iconImageId(R.id.native_ad_icon_image)
            .titleId(R.id.native_ad_title).textId(R.id.native_ad_text).build();

    MoPubNativeAdPositioning.MoPubServerPositioning adPositioning = MoPubNativeAdPositioning
            .serverPositioning();//from  w  w  w  .  j  a  v a 2  s . co  m
    final MoPubNativeAdRenderer adRenderer = new MoPubNativeAdRenderer(mopubViewBinder);
    moPubAdAdapter = new MoPubAdAdapter(this, adapter, adPositioning);
    moPubAdAdapter.registerAdRenderer(adRenderer);

    poemsList.setAdapter(moPubAdAdapter);
}

From source file:edu.pdx.cecs.orcycle.FragmentSavedNotesSection.java

void populateNoteList(ListView lv) {
    // Get list from the real phone database. W00t!
    final DbAdapter mDb = new DbAdapter(getActivity());
    //mDb.open();
    mDb.openReadOnly();//from w ww.  j  a  v  a 2 s  .c o  m
    try {
        allNotes = mDb.fetchAllNotes();
        Log.e(MODULE_TAG, "------------------> populateNoteList()");

        String[] from = new String[] { "noteseverity", "noterecorded" };
        int[] to = new int[] { R.id.tvSnliNoteSeverity, R.id.tvSnliRecorded };

        sna = new SavedNotesAdapter(getActivity(), R.layout.saved_notes_list_item, allNotes, from, to,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        lv.setAdapter(sna);
    } catch (SQLException ex) {
        Log.e(MODULE_TAG, ex.getMessage());
        // Do nothing, for now!
    } catch (Exception ex) {
        Log.e(MODULE_TAG, ex.getMessage());
    }
    mDb.close();

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int pos, long noteId) {
            Log.v(MODULE_TAG,
                    "onItemClick (id = " + String.valueOf(noteId) + ", pos = " + String.valueOf(pos) + ")");
            try {
                if (mActionModeNote == null) {

                    // If the note has just been recently scheduled, we won't ask the user
                    // if they want to upload it.  This fixes a bug whereby the note is
                    // in the process of uploading, but the user wants to see it now.
                    if (NoteUploader.isPending(noteId)) {
                        transitionToNoteMapActivity(noteId);
                    } else {
                        final DbAdapter mDb = new DbAdapter(getActivity());
                        mDb.openReadOnly();
                        try {
                            int noteStatus = mDb.getNoteStatus(noteId);
                            if (noteStatus == 2) {
                                transitionToNoteMapActivity(noteId);
                            } else if (noteStatus == 1) {
                                buildAlertMessageUnuploadedNoteClicked(noteId);
                            }
                        } catch (Exception ex) {
                            Log.e(MODULE_TAG, ex.getMessage());
                        } finally {
                            mDb.close();
                        }
                    }
                } else {
                    // highlight
                    if (noteIdArray.indexOf(noteId) > -1) {
                        noteIdArray.remove(noteId);
                        v.setBackgroundColor(Color.parseColor("#80ffffff"));
                    } else {
                        noteIdArray.add(noteId);
                        v.setBackgroundColor(Color.parseColor("#ff33b5e5"));
                    }
                    // Toast.makeText(getActivity(), "Selected: " + noteIdArray,
                    // Toast.LENGTH_SHORT).show();
                    if (noteIdArray.size() == 0) {
                        saveMenuItemDelete.setEnabled(false);
                    } else {
                        saveMenuItemDelete.setEnabled(true);
                    }

                    mActionModeNote.setTitle(noteIdArray.size() + " Selected");
                }
            } catch (Exception ex) {
                Log.e(MODULE_TAG, ex.getMessage());
            }
        }
    });

    registerForContextMenu(lv);
}

From source file:com.android.mms.quickmessage.QuickMessagePopup.java

/**
 * This displays the Templates selection dialog
 *//*w  w  w.j a  va 2s .c  o  m*/
@Override
protected Dialog onCreateDialog(int id, Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    switch (id) {
    case DIALOG_TEMPLATE_NOT_AVAILABLE:
        builder.setTitle(R.string.template_not_present_error_title);
        builder.setMessage(R.string.template_not_present_error);
        return builder.create();

    case DIALOG_TEMPLATE_SELECT:
        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.template_select);
        mTemplatesCursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null,
                new String[] { Template.TEXT }, new int[] { android.R.id.text1 },
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        builder.setAdapter(mTemplatesCursorAdapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Get the selected template and text
                Cursor c = (Cursor) mTemplatesCursorAdapter.getItem(which);
                String text = c.getString(c.getColumnIndex(Template.TEXT));

                // Get the currently visible message and append text
                QuickMessage qm = mMessageList.get(mCurrentPage);
                if (qm != null) {
                    // insert the template text at the cursor location or replace selected
                    int start = qm.getEditText().getSelectionStart();
                    int end = qm.getEditText().getSelectionEnd();
                    qm.getEditText().getText().replace(Math.min(start, end), Math.max(start, end), text);
                }
            }
        });
        return builder.create();
    }
    return super.onCreateDialog(id, args);
}