use of android.database.ContentObserver in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class ContactsContentObserver method registerObserver.
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);
}
use of android.database.ContentObserver in project android_frameworks_base by DirtyUnicorns.
the class BatteryService method onBootPhase.
@Override
public void onBootPhase(int phase) {
if (phase == PHASE_ACTIVITY_MANAGER_READY) {
// check our power situation now that it is safe to display the shutdown dialog.
synchronized (mLock) {
ContentObserver obs = new ContentObserver(mHandler) {
@Override
public void onChange(boolean selfChange) {
synchronized (mLock) {
updateBatteryWarningLevelLocked();
}
}
};
final ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL), false, obs, UserHandle.USER_ALL);
updateBatteryWarningLevelLocked();
}
} else if (phase == PHASE_BOOT_COMPLETED) {
SettingsObserver observer = new SettingsObserver(new Handler());
observer.observe();
}
}
use of android.database.ContentObserver in project android_frameworks_base by DirtyUnicorns.
the class PowerUI method start.
public void start() {
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mHardwarePropertiesManager = (HardwarePropertiesManager) mContext.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE);
mScreenOffTime = mPowerManager.isScreenOn() ? -1 : SystemClock.elapsedRealtime();
mWarnings = new PowerNotificationWarnings(mContext, getComponent(PhoneStatusBar.class));
ContentObserver obs = new ContentObserver(mHandler) {
@Override
public void onChange(boolean selfChange) {
updateBatteryWarningLevels();
}
};
final ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(Settings.Global.getUriFor(Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL), false, obs, UserHandle.USER_ALL);
updateBatteryWarningLevels();
mReceiver.init();
initTemperatureWarning();
}
use of android.database.ContentObserver in project android_frameworks_base by DirtyUnicorns.
the class DevicePolicyManagerServiceTestable method notifyChangeToContentObserver.
public void notifyChangeToContentObserver(Uri uri, int userHandle) {
ContentObserver co = mMockInjector.mContentObservers.get(new Pair<Uri, Integer>(uri, userHandle));
if (co != null) {
// notify synchronously
co.onChange(false, uri, userHandle);
}
// Notify USER_ALL observer too.
co = mMockInjector.mContentObservers.get(new Pair<Uri, Integer>(uri, UserHandle.USER_ALL));
if (co != null) {
// notify synchronously
co.onChange(false, uri, userHandle);
}
}
use of android.database.ContentObserver in project XobotOS by xamarin.
the class ContentQueryMap method setKeepUpdated.
/**
* Change whether or not the ContentQueryMap will register with the cursor's ContentProvider
* for change notifications. If you use a ContentQueryMap in an activity you should call this
* with false in onPause(), which means you need to call it with true in onResume()
* if want it to be kept updated.
* @param keepUpdated if true the ContentQueryMap should be registered with the cursor's
* ContentProvider, false otherwise
*/
public void setKeepUpdated(boolean keepUpdated) {
if (keepUpdated == mKeepUpdated)
return;
mKeepUpdated = keepUpdated;
if (!mKeepUpdated) {
mCursor.unregisterContentObserver(mContentObserver);
mContentObserver = null;
} else {
if (mHandlerForUpdateNotifications == null) {
mHandlerForUpdateNotifications = new Handler();
}
if (mContentObserver == null) {
mContentObserver = new ContentObserver(mHandlerForUpdateNotifications) {
@Override
public void onChange(boolean selfChange) {
// let it query lazily when they ask for the values.
if (countObservers() != 0) {
requery();
} else {
mDirty = true;
}
}
};
}
mCursor.registerContentObserver(mContentObserver);
// mark dirty, since it is possible the cursor's backing data had changed before we
// registered for changes
mDirty = true;
}
}
Aggregations