Java 类android.database.ContentObserver 实例源码
项目:keepass2android
文件:UserDictionary.java
public UserDictionary(Context context, String locale) {
super(context, Suggest.DIC_USER);
mLocale = locale;
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
setRequiresReload(true);
}
});
loadDictionary();
}
项目:PeSanKita-android
文件:ConversationListActivity.java
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w(TAG, "Detected android contact data changed, refreshing cache");
RecipientFactory.clearCache(ConversationListActivity.this);
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
chatsFragment.getListAdapter().notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
项目:Cable-Android
文件:ConversationListActivity.java
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w(TAG, "Detected android contact data changed, refreshing cache");
RecipientFactory.clearCache(ConversationListActivity.this);
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
fragment.getListAdapter().notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
项目:AOSP-Kayboard-7.1.2
文件:ContactsContentObserver.java
public void registerObserver(final ContactsChangedListener listener) {
if (!PermissionsUtil.checkAllPermissionsGranted(
mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Not registering the observer.");
// do nothing if we do not have the permission to read contacts.
return;
}
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "registerObserver()");
}
mContactsChangedListener = listener;
mContentObserver = new ContentObserver(null /* handler */) {
@Override
public void onChange(boolean self) {
ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD)
.execute(ContactsContentObserver.this);
}
};
final ContentResolver contentResolver = mContext.getContentResolver();
contentResolver.registerContentObserver(Contacts.CONTENT_URI, true, mContentObserver);
}
项目:KeePass2Android
文件:UserDictionary.java
public UserDictionary(Context context, String locale) {
super(context, Suggest.DIC_USER);
mLocale = locale;
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
setRequiresReload(true);
}
});
loadDictionary();
}
项目:android_packages_apps_tv
文件:ChannelDataManager.java
@VisibleForTesting
ChannelDataManager(Context context, TvInputManagerHelper inputManager,
ContentResolver contentResolver) {
mContext = context;
mInputManager = inputManager;
mContentResolver = contentResolver;
mChannelComparator = new Channel.DefaultComparator(context, inputManager);
// Detect duplicate channels while sorting.
mChannelComparator.setDetectDuplicatesEnabled(true);
mHandler = new ChannelDataManagerHandler(this);
mChannelObserver = new ContentObserver(mHandler) {
@Override
public void onChange(boolean selfChange) {
if (!mHandler.hasMessages(MSG_UPDATE_CHANNELS)) {
mHandler.sendEmptyMessage(MSG_UPDATE_CHANNELS);
}
}
};
mStoreBrowsableInSharedPreferences = !PermissionUtils.hasAccessAllEpg(mContext);
mBrowsableSharedPreferences = context.getSharedPreferences(
SharedPreferencesUtils.SHARED_PREF_BROWSABLE, Context.MODE_PRIVATE);
}
项目:android_packages_apps_tv
文件:ChannelDataManagerTest.java
@Override
public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) {
super.notifyChange(uri, observer, syncToNetwork);
if (DEBUG) {
Log.d(TAG, "onChanged(uri=" + uri + ", observer=" + observer + ") - Notification "
+ (mNotifyDisabled ? "disabled" : "enabled"));
}
if (mNotifyDisabled) {
return;
}
// Do not call {@link ContentObserver#onChange} directly to run it on the correct
// thread.
if (observer != null) {
observer.dispatchChange(false, uri);
} else {
mChannelDataManager.getContentObserver().dispatchChange(false, uri);
}
}
项目:forsuredbandroid
文件:BaseResolverContentObserver.java
public BaseResolverContentObserver(Context context,
final Resolver<R, Uri, FSContentValues, ?, ?, ?, ?> resolver,
Handler handler,
final boolean deliverSelfNotifications) {
this.context = context;
this.tableUris = UriEvaluator.tableReferences(resolver.currentLocator());
for (final Uri tableUri : tableUris) {
contentObservers.put(tableUri, new ContentObserver(handler) {
@Override
public boolean deliverSelfNotifications() {
return deliverSelfNotifications;
}
@Override
public void onChange(boolean selfChange) {
BaseResolverContentObserver.this.onChange(selfChange, tableUri, resolver);
}
});
}
}
项目:TextSecure
文件:ConversationListActivity.java
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w("ConversationListActivity", "detected android contact data changed, refreshing cache");
// TODO only clear updated recipients from cache
RecipientFactory.clearCache();
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
((ConversationListAdapter)fragment.getListAdapter()).notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
项目:android-image-picker
文件:ImagePickerActivity.java
@Override
protected void onStart() {
super.onStart();
if (isCameraOnly) {
return;
}
if (handler == null) {
handler = new Handler();
}
observer = new ContentObserver(handler) {
@Override
public void onChange(boolean selfChange) {
getData();
}
};
getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, observer);
}
项目:SQLite
文件:Observers.java
public <T> void registerObserver(@NonNull Context context, @NonNull Table<T> table,
@NonNull final BasicTableObserver observer) {
ContentObserver contentObserver = new DatabaseObserver() {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
MainHandler.getHandler().post(new Runnable() {
@Override
public void run() {
observer.onTableChanged();
}
});
}
};
context.getContentResolver().registerContentObserver(table.getUri(), false, contentObserver);
mObservers.add(new Pair<Object, ContentObserver>(observer, contentObserver));
}
项目:SQLite
文件:Observers.java
public <T> void registerObserver(@NonNull Context context, @NonNull final Table<T> table,
@NonNull final ContentTableObserver<T> observer, @NonNull final Where where) {
ContentObserver contentObserver = new DatabaseObserver() {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
RxSQLite.get().query(table, where)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<List<T>>() {
@Override
public void accept(List<T> list) throws Exception {
observer.onTableChanged(list);
}
});
}
};
context.getContentResolver().registerContentObserver(table.getUri(), false, contentObserver);
mObservers.add(new Pair<Object, ContentObserver>(observer, contentObserver));
}
项目:hackerskeyboard
文件:UserDictionary.java
public UserDictionary(Context context, String locale) {
super(context, Suggest.DIC_USER);
mLocale = locale;
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
setRequiresReload(true);
}
});
loadDictionary();
}
项目:FMTech
文件:DownloadManagerLegacyImpl.java
protected DownloadManagerLegacyImpl(Context paramContext)
{
this.mContentResolver = paramContext.getContentResolver();
HandlerThread localHandlerThread = BackgroundThreadFactory.createHandlerThread("download-manager-thread");
localHandlerThread.start();
this.mHandler = new Handler(localHandlerThread.getLooper());
this.mContentObserver = new ContentObserver(this.mHandler)
{
public final boolean deliverSelfNotifications()
{
return false;
}
public final void onChange(boolean paramAnonymousBoolean)
{
DownloadManagerLegacyImpl.access$000(DownloadManagerLegacyImpl.this);
}
};
}
项目:TextSecureSMP
文件:ConversationListActivity.java
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w(TAG, "detected android contact data changed, refreshing cache");
// TODO only clear updated recipients from cache
RecipientFactory.clearCache();
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
fragment.getListAdapter().notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
项目:Silence
文件:ConversationListActivity.java
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w(TAG, "Detected android contact data changed, refreshing cache");
RecipientFactory.clearCache();
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
fragment.getListAdapter().notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
项目:mc_backup
文件:ReadingListHelper.java
public ReadingListHelper(Context context, GeckoProfile profile, OnReadingListEventListener listener) {
this.context = context;
this.db = profile.getDB();
this.readingListAccessor = db.getReadingListAccessor();
EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener) this,
"Reader:AddToList", "Reader:UpdateList", "Reader:FaviconRequest", "Reader:ListStatusRequest", "Reader:RemoveFromList");
contentObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
if (fetchInBackground) {
fetchContent();
}
}
};
this.readingListAccessor.registerContentObserver(context, contentObserver);
onReadingListEventListener = listener;
}
项目:feeds
文件:FeedEntryListFragment.java
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
log.fine("On activity created");
adapter = createListAdapter();
setListAdapter(adapter);
refreshContentObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
adapter.setRefreshRequired(isResumed());
}
};
long id = stateProvider.getFeedReader().feedId;
Uri uri = id == -1
? FeedConfig.CONTENT_URI
: Uri.withAppendedPath(FeedConfig.CONTENT_URI, Long.toString(id));
log.fine("On create, registering content observer: " + uri);
getActivity().getContentResolver().registerContentObserver(
uri, true, refreshContentObserver
);
}
项目:devnexus-android
文件:SetupFragment.java
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
presentationObersever = new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
if (getActivity() != null) {
((MainActivity) getActivity()).switchFragment(PresentationExplorerFragment.newInstance(), MainActivity.BackStackOperation.RESET, "SessionListFragment");
}
}
};
resolver = getActivity().getContentResolver();
return inflater.inflate(R.layout.setup_layout, null);
}
项目:reark
文件:ContentProviderStoreCore.java
@NonNull
@Override
protected ContentObserver getContentObserver() {
return new ContentObserver(createHandler(getClass().getSimpleName())) {
@Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
getOnce(uri)
.doOnSuccess(item -> Log.v(TAG, format("onChange(%1s)", uri)))
.map(item -> new StoreItem<>(getIdForUri(uri), item))
.subscribe(subjectCache::onNext,
error -> Log.e(TAG, "Cannot retrieve the item: " + uri, error));
}
};
}
项目:FullRobolectricTestSample
文件:ContentResolverTest.java
@Test
public void shouldRegisterContentObservers() throws Exception {
TestContentObserver co = new TestContentObserver(null);
ShadowContentResolver scr = Robolectric.shadowOf(contentResolver);
assertThat(scr.getContentObserver(EXTERNAL_CONTENT_URI)).isNull();
contentResolver.registerContentObserver(EXTERNAL_CONTENT_URI, true, co);
assertThat(scr.getContentObserver(EXTERNAL_CONTENT_URI)).isSameAs((ContentObserver) co);
assertThat(co.changed).isFalse();
contentResolver.notifyChange(EXTERNAL_CONTENT_URI, null);
assertThat(co.changed).isTrue();
scr.clearContentObservers();
assertThat(scr.getContentObserver(EXTERNAL_CONTENT_URI)).isNull();
}
项目:arca-android
文件:SimpleOperationTest.java
public void testSimpleOperationNotifiesChangeOnSuccess() {
final AssertionLatch latch = new AssertionLatch(1);
final MockContext context = new MockContext() {
@Override
public ContentResolver getContentResolver() {
return new MockContentResolver() {
@Override
public void notifyChange(final Uri u, final ContentObserver o) {
latch.countDown();
}
};
}
};
final TestSimpleOperation operation = new TestSimpleOperation(Uri.EMPTY);
operation.onSuccess(context, null);
latch.assertComplete();
}
项目:Securecom-Messaging
文件:ConversationListActivity.java
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w("ConversationListActivity", "detected android contact data changed, refreshing cache");
// TODO only clear updated recipients from cache
RecipientFactory.clearCache();
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
((ConversationListAdapter)fragment.getListAdapter()).notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
项目:Securecom-Text
文件:ConversationListActivity.java
private void initializeContactUpdatesReceiver() {
observer = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.w("ConversationListActivity", "detected android contact data changed, refreshing cache");
// TODO only clear updated recipients from cache
RecipientFactory.clearCache();
ConversationListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
((ConversationListAdapter)fragment.getListAdapter()).notifyDataSetChanged();
}
});
}
};
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
true, observer);
}
项目:androidtv-sample-inputs
文件:BaseTvInputService.java
@Override
public void onCreate() {
super.onCreate();
// Create background thread
mDbHandlerThread = new HandlerThread(getClass().getSimpleName());
mDbHandlerThread.start();
// Initialize the channel map and set observer for changes
mContentResolver = BaseTvInputService.this.getContentResolver();
updateChannelMap();
mChannelObserver = new ContentObserver(new Handler(mDbHandlerThread.getLooper())) {
@Override
public void onChange(boolean selfChange) {
updateChannelMap();
}
};
mContentResolver.registerContentObserver(TvContract.Channels.CONTENT_URI, true,
mChannelObserver);
// Setup our BroadcastReceiver
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED);
intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED);
registerReceiver(mParentalControlsBroadcastReceiver, intentFilter);
}
项目:muzei
文件:WidgetUpdater.java
@Override
public void onCreate(@NonNull final LifecycleOwner owner) {
// Set up a ContentObserver to update widgets whenever the artwork changes
mWidgetContentObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(final boolean selfChange, final Uri uri) {
new AppWidgetUpdateTask(mContext, false)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
};
mContext.getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI,
true, mWidgetContentObserver);
mContext.getContentResolver().registerContentObserver(MuzeiContract.Sources.CONTENT_URI,
true, mWidgetContentObserver);
// Update the widget now that the wallpaper is active to enable the 'Next' button if supported
mWidgetContentObserver.onChange(true);
}
项目:ShortcutBar
文件:EditShortcutBar.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_shortcut_bar);
mOnPause = false;
mOrderHasChanged = false;
mDatabaseHelper = new DatabaseHelper(EditShortcutBar.this);
HandlerThread thread = new HandlerThread(TAG);
thread.setPriority(Thread.NORM_PRIORITY);
thread.start();
mNonUiHandler = new NonUiHandler(thread.getLooper());
mContentObserverShortcutTable = new ContentObserver(mNonUiHandler) {
public void onChange(boolean selfChange) {
LogUtils.d(TAG, "onChange: ", selfChange, " , mOnPause: ", mOnPause);
if (mOnPause) {
mDirtyFlag = true;
}
}
};
getContentResolver().registerContentObserver(ShortcutTable.CONTENT_URI, true, mContentObserverShortcutTable);
findViews();
}
项目:devnexus-android
文件:SetupFragment.java
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
presentationObersever = new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
if (getActivity() != null) {
((MainActivity) getActivity()).switchFragment(PresentationExplorerFragment.newInstance(), MainActivity.BackStackOperation.RESET, "SessionListFragment");
}
}
};
resolver = getActivity().getContentResolver();
return inflater.inflate(R.layout.setup_layout, null);
}
项目:storio
文件:DefaultStorIOContentResolverTest.java
@Test
public void shouldUseCustomHandlerForContentObservers() {
ContentResolver contentResolver = mock(ContentResolver.class);
ArgumentCaptor<ContentObserver> observerArgumentCaptor = ArgumentCaptor.forClass(ContentObserver.class);
doNothing().when(contentResolver)
.registerContentObserver(any(Uri.class), anyBoolean(), observerArgumentCaptor.capture());
Handler handler = mock(Handler.class);
StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder()
.contentResolver(contentResolver)
.contentObserverHandler(handler)
.defaultRxScheduler(null)
.build();
Disposable disposable = storIOContentResolver.observeChangesOfUri(mock(Uri.class), LATEST).subscribe();
assertThat(observerArgumentCaptor.getAllValues()).hasSize(1);
ContentObserver contentObserver = observerArgumentCaptor.getValue();
Object actualHandler = ReflectionHelpers.getField(contentObserver, "mHandler");
assertThat(actualHandler).isEqualTo(handler);
disposable.dispose();
}
项目:storio
文件:RxChangesObserverTest.java
@Test
public void shouldDoNothingIfUriListEmpty() {
for (int sdkVersion = MIN_SDK_VERSION; sdkVersion < MAX_SDK_VERSION; sdkVersion++) {
ContentResolver contentResolver = mock(ContentResolver.class);
Disposable disposable = RxChangesObserver
.observeChanges(
contentResolver,
Collections.<Uri>emptySet(),
mock(Handler.class),
sdkVersion,
BackpressureStrategy.MISSING
)
.subscribe();
disposable.dispose();
verify(contentResolver, never()).registerContentObserver(any(Uri.class), anyBoolean(), any(ContentObserver.class));
verify(contentResolver, never()).unregisterContentObserver(any(ContentObserver.class));
}
}
项目:TimePicker
文件:HapticFeedbackController.java
public HapticFeedbackController(Context context) {
mContext = context;
mContentObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
mIsGloballyEnabled = checkGlobalSetting(mContext);
}
};
}
项目:keepass2android
文件:ContactsDictionary.java
public ContactsDictionary(Context context, int dicTypeId) {
super(context, dicTypeId);
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
cres.registerContentObserver(
Contacts.CONTENT_URI, true,mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
setRequiresReload(true);
}
});
loadDictionary();
}
项目:AssistantBySDK
文件:HapticFeedbackController.java
public HapticFeedbackController(Context context) {
mContext = context;
mContentObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
mIsGloballyEnabled = checkGlobalSetting(mContext);
}
};
}
项目:ScreenshotMonitor
文件:ScreenshotMonitorManager.java
/**
* 开始监测系统截屏,需要申请 Manifest.permission.READ_EXTERNAL_STORAGE 权限
*/
public void doMonitor(Context context) {
mContext = context;
mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange, Uri uri) {
if (uri.toString().contains(EXTERNAL_CONTENT_URI)) {
checkPermission(mContext);
Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MEDIA_PROJECTION_API_16, null, null, MediaStore.Images.ImageColumns.DATE_ADDED + " DESC");
if (cursor != null && cursor.moveToFirst()) {
final String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
long dateAdded = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATE_ADDED));
int width = cursor.getColumnIndex(MediaStore.Images.ImageColumns.WIDTH);
int height = cursor.getColumnIndex(MediaStore.Images.ImageColumns.HEIGHT);
if (isFromScreenshot(path, dateAdded, width, height)) {
onMonitorSuccess(path);
}
Log.d(TAG, "path: " + path + "dateAdded: " + dateAdded);
}
} catch (Exception e) {
} finally {
cursor.close();
}
}
}
};
context.getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, mObserver);
}
项目:PictureShow
文件:MyMergeSortCursor.java
@Override
public void registerContentObserver(ContentObserver observer) {
int length = mCursors.length;
for (int i = 0 ; i < length ; i++) {
if (mCursors[i] != null) {
mCursors[i].registerContentObserver(observer);
}
}
}
项目:PictureShow
文件:MyMergeSortCursor.java
@Override
public void unregisterContentObserver(ContentObserver observer) {
int length = mCursors.length;
for (int i = 0 ; i < length ; i++) {
if (mCursors[i] != null) {
mCursors[i].unregisterContentObserver(observer);
}
}
}
项目:springreplugin
文件:PluginProviderClient.java
/**
* 调用插件里的Provider
*
* @see android.content.ContentResolver#registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer)
*/
public static void registerContentObserver(Context c, Uri uri, boolean notifyForDescendents, ContentObserver observer) {
try {
Uri turi = toCalledUri(c, uri);
c.getContentResolver().registerContentObserver(turi, notifyForDescendents, observer);
} catch (Throwable e) {
if (LOGR) {
e.printStackTrace();
}
}
}
项目:aos-MediaLib
文件:AutoScrapeService.java
/**
* Register content observer and start autoscrap if enabled
* @param context
*/
public static void registerObserver(final Context context) {
final Context appContext = context.getApplicationContext();
appContext.getContentResolver().registerContentObserver(VideoStore.ALL_CONTENT_URI, true, new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
if (PreferenceManager.getDefaultSharedPreferences(appContext).getBoolean(KEY_ENABLE_AUTO_SCRAP, true)) {
AutoScrapeService.startService(appContext);
}
}
});
}
项目:AOSP-Kayboard-7.1.2
文件:AndroidWordLevelSpellCheckerSession.java
AndroidWordLevelSpellCheckerSession(final AndroidSpellCheckerService service) {
mService = service;
final ContentResolver cres = service.getContentResolver();
mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
mSuggestionsCache.clearCache();
}
};
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver);
}
项目:KeePass2Android
文件:ContactsDictionary.java
public ContactsDictionary(Context context, int dicTypeId) {
super(context, dicTypeId);
// Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed.
ContentResolver cres = context.getContentResolver();
cres.registerContentObserver(
Contacts.CONTENT_URI, true,mObserver = new ContentObserver(null) {
@Override
public void onChange(boolean self) {
setRequiresReload(true);
}
});
loadDictionary();
}