Java Code Examples for android.database.Cursor#registerDataSetObserver()
The following examples show how to use
android.database.Cursor#registerDataSetObserver() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CircularViewCursorAdapter.java From CircularView with Apache License 2.0 | 6 votes |
void init(final Cursor c, int flags) { if ((flags & CursorAdapter.FLAG_AUTO_REQUERY) == CursorAdapter.FLAG_AUTO_REQUERY) { flags |= CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER; mAutoRequery = true; } else { mAutoRequery = false; } boolean cursorPresent = c != null; mCursor = c; mDataValid = cursorPresent; mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; if ((flags & CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) == CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { mChangeObserver = new ChangeObserver(); mDataSetObserver = new MyDataSetObserver(); } else { mChangeObserver = null; mDataSetObserver = null; } if (cursorPresent) { if (mChangeObserver != null) c.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver); } }
Example 2
Source File: RecyclerViewCursorAdapter.java From BLEMeshChat with Mozilla Public License 2.0 | 6 votes |
void init(Context context, Cursor c, int flags) { boolean cursorPresent = c != null; mCursor = c; mDataValid = cursorPresent; mContext = context; mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) { mChangeObserver = new ChangeObserver(); mDataSetObserver = new MyDataSetObserver(); } else { mChangeObserver = null; mDataSetObserver = null; } if (cursorPresent) { if (mChangeObserver != null) c.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver); } setHasStableIds(true); }
Example 3
Source File: CircularViewCursorAdapter.java From CircularView with Apache License 2.0 | 6 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. * * @param newCursor The new cursor to be used. * @return Returns the previously set Cursor, or null if there was not one. * If the given new Cursor is the same instance is the previously set * Cursor, null is also returned. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver); if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (newCursor != null) { if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver); mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetInvalidated(); } return oldCursor; }
Example 4
Source File: CursorAdapter.java From V.FlyoutTest with MIT License | 6 votes |
void init(Context context, Cursor c, int flags) { if ((flags & FLAG_AUTO_REQUERY) == FLAG_AUTO_REQUERY) { flags |= FLAG_REGISTER_CONTENT_OBSERVER; mAutoRequery = true; } else { mAutoRequery = false; } boolean cursorPresent = c != null; mCursor = c; mDataValid = cursorPresent; mContext = context; mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) { mChangeObserver = new ChangeObserver(); mDataSetObserver = new MyDataSetObserver(); } else { mChangeObserver = null; mDataSetObserver = null; } if (cursorPresent) { if (mChangeObserver != null) c.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver); } }
Example 5
Source File: CursorAdapter.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. * * @param newCursor The new cursor to be used. * @return Returns the previously set Cursor, or null if there wasa not one. * If the given new Cursor is the same instance is the previously set * Cursor, null is also returned. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver); if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (newCursor != null) { if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver); mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetInvalidated(); } return oldCursor; }
Example 6
Source File: CursorAdapter.java From V.FlyoutTest with MIT License | 6 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. * * @param newCursor The new cursor to be used. * @return Returns the previously set Cursor, or null if there wasa not one. * If the given new Cursor is the same instance is the previously set * Cursor, null is also returned. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver); if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (newCursor != null) { if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver); mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetInvalidated(); } return oldCursor; }
Example 7
Source File: GroupingListAdapter.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
public void changeCursor(Cursor cursor) { if (cursor == mCursor) { return; } if (mCursor != null) { mCursor.unregisterContentObserver(mChangeObserver); mCursor.unregisterDataSetObserver(mDataSetObserver); mCursor.close(); } mCursor = cursor; resetCache(); findGroups(); if (cursor != null) { cursor.registerContentObserver(mChangeObserver); cursor.registerDataSetObserver(mDataSetObserver); mRowIdColumnIndex = cursor.getColumnIndexOrThrow("_id"); notifyDataSetChanged(); } else { // notify the observers about the lack of a data set notifyDataSetInvalidated(); } }
Example 8
Source File: CursorAdapter.java From v2ex with Apache License 2.0 | 6 votes |
void init(Context context, Cursor c, int flags) { boolean cursorPresent = c != null; mCursor = c; mDataValid = cursorPresent; mContext = context; mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) { mChangeObserver = new ChangeObserver(); mDataSetObserver = new MyDataSetObserver(); } else { mChangeObserver = null; mDataSetObserver = null; } if (cursorPresent) { if (mChangeObserver != null) c.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver); } setHasStableIds(true); }
Example 9
Source File: CursorAdapter.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
void init(Context context, Cursor c, int flags) { if ((flags & FLAG_AUTO_REQUERY) == FLAG_AUTO_REQUERY) { flags |= FLAG_REGISTER_CONTENT_OBSERVER; mAutoRequery = true; } else { mAutoRequery = false; } boolean cursorPresent = c != null; mCursor = c; mDataValid = cursorPresent; mContext = context; mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) { mChangeObserver = new ChangeObserver(); mDataSetObserver = new MyDataSetObserver(); } else { mChangeObserver = null; mDataSetObserver = null; } if (cursorPresent) { if (mChangeObserver != null) c.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver); } }
Example 10
Source File: AlphabetIndexer.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Constructs the indexer. * @param cursor the cursor containing the data set * @param sortedColumnIndex the column number in the cursor that is sorted * alphabetically * @param alphabet string containing the alphabet, with space as the first character. * For example, use the string " ABCDEFGHIJKLMNOPQRSTUVWXYZ" for English indexing. * The characters must be uppercase and be sorted in ascii/unicode order. Basically * characters in the alphabet will show up as preview letters. */ public AlphabetIndexer(Cursor cursor, int sortedColumnIndex, CharSequence alphabet) { mDataCursor = cursor; mColumnIndex = sortedColumnIndex; mAlphabet = alphabet; mAlphabetLength = alphabet.length(); mAlphabetArray = new String[mAlphabetLength]; for (int i = 0; i < mAlphabetLength; i++) { mAlphabetArray[i] = Character.toString(mAlphabet.charAt(i)); } mAlphaMap = new SparseIntArray(mAlphabetLength); if (cursor != null) { cursor.registerDataSetObserver(this); } // Get a Collator for the current locale for string comparisons. mCollator = java.text.Collator.getInstance(); mCollator.setStrength(java.text.Collator.PRIMARY); }
Example 11
Source File: CursorTreeAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void changeCursor(Cursor cursor, boolean releaseCursors) { if (cursor == mCursor) return; deactivate(); mCursor = cursor; if (cursor != null) { cursor.registerContentObserver(mContentObserver); cursor.registerDataSetObserver(mDataSetObserver); mRowIDColumn = cursor.getColumnIndex("_id"); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(releaseCursors); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetInvalidated(); } }
Example 12
Source File: CursorAdapter.java From letv with Apache License 2.0 | 5 votes |
void init(Context context, Cursor c, int flags) { boolean cursorPresent = true; if ((flags & 1) == 1) { flags |= 2; this.mAutoRequery = true; } else { this.mAutoRequery = false; } if (c == null) { cursorPresent = false; } this.mCursor = c; this.mDataValid = cursorPresent; this.mContext = context; this.mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; if ((flags & 2) == 2) { this.mChangeObserver = new ChangeObserver(this); this.mDataSetObserver = new MyDataSetObserver(this, null); } else { this.mChangeObserver = null; this.mDataSetObserver = null; } if (cursorPresent) { if (this.mChangeObserver != null) { c.registerContentObserver(this.mChangeObserver); } if (this.mDataSetObserver != null) { c.registerDataSetObserver(this.mDataSetObserver); } } }
Example 13
Source File: CursorAdapter.java From letv with Apache License 2.0 | 5 votes |
public Cursor swapCursor(Cursor newCursor) { if (newCursor == this.mCursor) { return null; } Cursor oldCursor = this.mCursor; if (oldCursor != null) { if (this.mChangeObserver != null) { oldCursor.unregisterContentObserver(this.mChangeObserver); } if (this.mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(this.mDataSetObserver); } } this.mCursor = newCursor; if (newCursor != null) { if (this.mChangeObserver != null) { newCursor.registerContentObserver(this.mChangeObserver); } if (this.mDataSetObserver != null) { newCursor.registerDataSetObserver(this.mDataSetObserver); } this.mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); this.mDataValid = true; notifyDataSetChanged(); return oldCursor; } this.mRowIDColumn = -1; this.mDataValid = false; notifyDataSetInvalidated(); return oldCursor; }
Example 14
Source File: CursorRecyclerAdapter.java From Ouroboros with GNU General Public License v3.0 | 5 votes |
void init(Cursor c) { boolean cursorPresent = c != null; mCursor = c; mDataValid = cursorPresent; mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; mChangeObserver = new ChangeObserver(); mDataSetObserver = new MyDataSetObserver(); if (cursorPresent) { if (mChangeObserver != null) c.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver); } }
Example 15
Source File: CursorAdapter.java From ExRecyclerViewLibrary with Apache License 2.0 | 5 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. * * @param newCursor The new cursor to be used. * @return Returns the previously set Cursor, or null if there wasa not one. * If the given new Cursor is the same instance is the previously set * Cursor, null is also returned. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver); if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (newCursor != null) { if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver); mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetChanged(); // notifyDataSetInvalidated(); } return oldCursor; }
Example 16
Source File: CursorPagerAdapter.java From android-open-project-demo with Apache License 2.0 | 5 votes |
void init(Context context, Cursor c, int flags) { if ((flags & FLAG_AUTO_REQUERY) == FLAG_AUTO_REQUERY) { flags |= FLAG_REGISTER_CONTENT_OBSERVER; mAutoRequery = true; } else { mAutoRequery = false; } boolean cursorPresent = c != null; mCursor = c; mDataValid = cursorPresent; mContext = context; mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) { mChangeObserver = new ChangeObserver(); mDataSetObserver = new MyDataSetObserver(); } else { mChangeObserver = null; mDataSetObserver = null; } if (cursorPresent) { if (mChangeObserver != null) { c.registerContentObserver(mChangeObserver); } if (mDataSetObserver != null) { c.registerDataSetObserver(mDataSetObserver); } } }
Example 17
Source File: RecyclerViewCursorAdapter.java From BLEMeshChat with Mozilla Public License 2.0 | 5 votes |
/** * Swap in a new Cursor, returning the old Cursor. Unlike * {@link #changeCursor(Cursor)}, the returned old Cursor is <em>not</em> * closed. * * @param newCursor The new cursor to be used. * @return Returns the previously set Cursor, or null if there wasa not one. * If the given new Cursor is the same instance is the previously set * Cursor, null is also returned. */ public Cursor swapCursor(Cursor newCursor) { if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver); if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver); } mCursor = newCursor; if (newCursor != null) { if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver); if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver); mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { mRowIDColumn = -1; mDataValid = false; // notify the observers about the lack of a data set notifyDataSetChanged(); // notifyDataSetInvalidated(); } return oldCursor; }
Example 18
Source File: CursorTreeAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
MyCursorHelper(Cursor cursor) { final boolean cursorPresent = cursor != null; mCursor = cursor; mDataValid = cursorPresent; mRowIDColumn = cursorPresent ? cursor.getColumnIndex("_id") : -1; mContentObserver = new MyContentObserver(); mDataSetObserver = new MyDataSetObserver(); if (cursorPresent) { cursor.registerContentObserver(mContentObserver); cursor.registerDataSetObserver(mDataSetObserver); } }
Example 19
Source File: CursorAdapter.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
void a(Context context, Cursor cursor, int i) { boolean flag = true; int j; if ((i & 1) == flag) { i |= 2; mAutoRequery = flag; } else { mAutoRequery = false; } if (cursor == null) { flag = false; } mCursor = cursor; mDataValid = flag; mContext = context; if (flag) { j = cursor.getColumnIndexOrThrow("_id"); } else { j = -1; } mRowIDColumn = j; if ((i & 2) == 2) { mChangeObserver = new b(this); mDataSetObserver = new c(this, null); } else { mChangeObserver = null; mDataSetObserver = null; } if (flag) { if (mChangeObserver != null) { cursor.registerContentObserver(mChangeObserver); } if (mDataSetObserver != null) { cursor.registerDataSetObserver(mDataSetObserver); } } }
Example 20
Source File: MediaStoreImageAdapter.java From libcommon with Apache License 2.0 | 4 votes |
@Nullable protected Cursor swapCursor(@Nullable final Cursor newCursor) { if (newCursor == mCursor) { return null; } Cursor oldCursor = mCursor; if (oldCursor != null) { if (mChangeObserver != null) { oldCursor.unregisterContentObserver(mChangeObserver); } if (mDataSetObserver != null) { oldCursor.unregisterDataSetObserver(mDataSetObserver); } } mCursor = newCursor; if (newCursor != null) { if (mChangeObserver != null) { newCursor.registerContentObserver(mChangeObserver); } if (mDataSetObserver != null) { newCursor.registerDataSetObserver(mDataSetObserver); } synchronized (mValues) { mValues.clear(); if (newCursor.moveToFirst()) { int pos = 0; do { info.loadFromCursor(newCursor); if (!mNeedValidate || info.canRead(mCr)) { mValues.add(pos); } pos++; } while (newCursor.moveToNext()); } } mDataValid = true; // notify the observers about the new cursor notifyDataSetChanged(); } else { synchronized (mValues) { mValues.clear(); } mDataValid = false; // notify the observers about the lack of a data set notifyDataSetInvalidated(); } return oldCursor; }