本文整理汇总了Java中android.database.Cursor.registerContentObserver方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.registerContentObserver方法的具体用法?Java Cursor.registerContentObserver怎么用?Java Cursor.registerContentObserver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.Cursor
的用法示例。
在下文中一共展示了Cursor.registerContentObserver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeCursor
import android.database.Cursor; //导入方法依赖的package包/类
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();
}
}
示例2: init
import android.database.Cursor; //导入方法依赖的package包/类
private 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);
}
示例3: init
import android.database.Cursor; //导入方法依赖的package包/类
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);
}
示例4: loadInBackground
import android.database.Cursor; //导入方法依赖的package包/类
@Override
public Cursor loadInBackground() {
Cursor newCursor = getCursor();
if (newCursor != null) {
newCursor.getCount();
newCursor.registerContentObserver(observer);
}
return newCursor;
}
示例5: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
/**
* 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;
}
示例6: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
/**
* 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;
}
示例7: loadInBackground
import android.database.Cursor; //导入方法依赖的package包/类
public Cursor loadInBackground() {
Cursor cursor = null;
try {
cursor = getContext().getContentResolver().query(this.mUri, this.mProjection, this.mSelection, this.mSelectionArgs, this.mSortOrder);
if (cursor != null) {
cursor.getCount();
cursor.registerContentObserver(this.mObserver);
}
} catch (Exception e) {
e.printStackTrace();
}
return cursor;
}
示例8: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
/**
* 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();
notifyItemRangeRemoved(0, oldCursor.getCount());
}
return oldCursor;
}
开发者ID:vikasdesale,项目名称:News24x7-news-from-every-part-of-the-world,代码行数:37,代码来源:CursorRecyclerViewAdapter.java
示例9: swapCursor
import android.database.Cursor; //导入方法依赖的package包/类
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;
}
示例10: loadInBackground
import android.database.Cursor; //导入方法依赖的package包/类
public Cursor loadInBackground() {
Cursor cursor;
synchronized (this) {
if (isLoadInBackgroundCanceled()) {
throw new OperationCanceledException();
}
this.mCancellationSignal = new CancellationSignal();
}
try {
cursor = ContentResolverCompat.query(getContext().getContentResolver(), this.mUri, this.mProjection, this.mSelection, this.mSelectionArgs, this.mSortOrder, this.mCancellationSignal);
if (cursor != null) {
cursor.getCount();
cursor.registerContentObserver(this.mObserver);
}
synchronized (this) {
this.mCancellationSignal = null;
}
return cursor;
} catch (RuntimeException ex) {
cursor.close();
throw ex;
} catch (Throwable th) {
synchronized (this) {
this.mCancellationSignal = null;
}
}
}
示例11: init
import android.database.Cursor; //导入方法依赖的package包/类
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.mDataSetObserver = new MyDataSetObserver();
} 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);
}
}
}
示例12: init
import android.database.Cursor; //导入方法依赖的package包/类
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);
}
}
开发者ID:vikasdesale,项目名称:News24x7-news-from-every-part-of-the-world,代码行数:15,代码来源:CursorRecyclerViewAdapter.java
示例13: registerContentObserver
import android.database.Cursor; //导入方法依赖的package包/类
@Override
public void registerContentObserver(ContentObserver observer) {
for (Cursor cursor : mCursors) {
cursor.registerContentObserver(observer);
}
}
示例14: testUpdateLeader
import android.database.Cursor; //导入方法依赖的package包/类
public void testUpdateLeader() {
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createLeaderValues();
Uri Uri = mContext.getContentResolver().
insert(LeaderContract.LeaderEntry.CONTENT_URI, values);
long leaderRowId = ContentUris.parseId(Uri);
// Verify we got a row back.
assertTrue(leaderRowId != -1);
Log.d(LOG_TAG, "New row id: " + leaderRowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(LeaderContract.LeaderEntry._ID, leaderRowId);
updatedValues.put(LeaderContract.LeaderEntry.COLUMN_USER_NAME, "Bob");
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor leaderCursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.CONTENT_URI, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
leaderCursor.registerContentObserver(tco);
int count = mContext.getContentResolver().update(
LeaderContract.LeaderEntry.CONTENT_URI, updatedValues, LeaderContract.LeaderEntry._ID + "= ?",
new String[]{Long.toString(leaderRowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
tco.waitForNotificationOrFail();
leaderCursor.unregisterContentObserver(tco);
leaderCursor.close();
Cursor cursor = mContext.getContentResolver().query(
LeaderContract.LeaderEntry.CONTENT_URI,
null,
LeaderContract.LeaderEntry._ID + " = " + leaderRowId,
null,
null
);
TestUtilities.validateCursor("testUpdateLeader. Error validating leader entry update.",
cursor, updatedValues);
cursor.close();
}
示例15: testUpdateFavoriteMovie
import android.database.Cursor; //导入方法依赖的package包/类
@Test
public void testUpdateFavoriteMovie() {
Context appContext = InstrumentationRegistry.getTargetContext();
// Create a new map of values, where column names are the keys
ContentValues values = TestUtilities.createTheWallValues();
Uri quoteUri = appContext.getContentResolver().
insert(FavoritesContract.FavoriteColumns.uriMovie, values);
long rowId = ContentUris.parseId(quoteUri);
// Verify we got a row back.
assertTrue(rowId != -1);
Log.d(LOG_TAG, "New row id: " + rowId);
ContentValues updatedValues = new ContentValues(values);
updatedValues.put(FavoritesContract.FavoriteColumns._ID, rowId);
updatedValues.put(FavoritesContract.FavoriteColumns.COLUMN_VOTE_COUNT, 250);
// Create a cursor with observer to make sure that the content provider is notifying
// the observers as expected
Cursor locationCursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriMovie, null, null, null, null);
TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
locationCursor.registerContentObserver(tco);
int count = appContext.getContentResolver().update(
FavoritesContract.FavoriteColumns.uriMovie, updatedValues,
FavoritesContract.FavoriteColumns._ID + "= ?", new String[] { Long.toString(rowId)});
assertEquals(count, 1);
// Test to make sure our observer is called. If not, we throw an assertion.
// If your code is failing here, it means that your content provider
// isn't calling getContext().getContentResolver().notifyChange(uri, null);
tco.waitForNotificationOrFail();
locationCursor.unregisterContentObserver(tco);
locationCursor.close();
// A cursor is your primary interface to the query results.
Cursor cursor = appContext.getContentResolver().query(
FavoritesContract.FavoriteColumns.uriMovie,
null, // projection
FavoritesContract.FavoriteColumns._ID + " = " + rowId,
null, // Values for the "where" clause
null // sort order
);
TestUtilities.validateCursor("testUpdateFavoriteMovie. Error validating quote entry update.",
cursor, updatedValues);
cursor.close();
}