use of android.database.ContentObserver in project muzei by romannurik.
the class FullScreenActivity method onCreateLoader.
@Override
public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
return new AsyncTaskLoader<Bitmap>(this) {
private ContentObserver mContentObserver;
private Bitmap mImage;
@Override
protected void onStartLoading() {
if (mImage != null) {
deliverResult(mImage);
}
if (mContentObserver == null) {
mContentObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
onContentChanged();
}
};
getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mContentObserver);
}
forceLoad();
}
@Override
public Bitmap loadInBackground() {
try {
mArtwork = MuzeiContract.Artwork.getCurrentArtwork(FullScreenActivity.this);
mImage = MuzeiContract.Artwork.getCurrentArtworkBitmap(FullScreenActivity.this);
return mImage;
} catch (FileNotFoundException e) {
Log.e(TAG, "Error getting artwork", e);
return null;
}
}
@Override
protected void onReset() {
super.onReset();
mImage = null;
if (mContentObserver != null) {
getContentResolver().unregisterContentObserver(mContentObserver);
}
}
};
}
use of android.database.ContentObserver in project Signal-Android by WhisperSystems.
the class ConversationListActivity method initializeContactUpdatesReceiver.
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);
}
use of android.database.ContentObserver in project storio by pushtorefresh.
the class RxChangesObserverTest method shouldRegisterOnlyOneContentObserverAfterSubscribingToObservableOnSdkVersionGreaterThan15.
@Test
public void shouldRegisterOnlyOneContentObserverAfterSubscribingToObservableOnSdkVersionGreaterThan15() {
for (int sdkVersion = 16; sdkVersion < MAX_SDK_VERSION; sdkVersion++) {
ContentResolver contentResolver = mock(ContentResolver.class);
final AtomicReference<ContentObserver> contentObserver = new AtomicReference<ContentObserver>();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
// Save reference to ContentObserver only once to assert that it was created once
if (contentObserver.get() == null) {
contentObserver.set((ContentObserver) invocation.getArguments()[2]);
} else if (contentObserver.get() != invocation.getArguments()[2]) {
throw new AssertionError("More than one ContentObserver was created");
}
return null;
}
}).when(contentResolver).registerContentObserver(any(Uri.class), eq(true), any(ContentObserver.class));
Set<Uri> uris = new HashSet<Uri>(3);
uris.add(mock(Uri.class));
uris.add(mock(Uri.class));
uris.add(mock(Uri.class));
Observable<Changes> observable = RxChangesObserver.observeChanges(contentResolver, uris, mock(Handler.class), sdkVersion);
// Should not register ContentObserver before subscribing to Observable
verify(contentResolver, times(0)).registerContentObserver(any(Uri.class), anyBoolean(), any(ContentObserver.class));
Subscription subscription = observable.subscribe();
for (Uri uri : uris) {
// Assert that same ContentObserver was registered for all uris
verify(contentResolver).registerContentObserver(same(uri), eq(true), same(contentObserver.get()));
}
subscription.unsubscribe();
}
}
use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.
the class PhoneWindowManager method init.
/** {@inheritDoc} */
@Override
public void init(Context context, IWindowManager windowManager, WindowManagerFuncs windowManagerFuncs) {
mContext = context;
mWindowManager = windowManager;
mWindowManagerFuncs = windowManagerFuncs;
mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
if (!mHeadless) {
// don't create KeyguardViewMediator if headless
mKeyguardMediator = new KeyguardViewMediator(context, null);
}
mHandler = new PolicyHandler();
mOrientationListener = new MyOrientationListener(mContext, mHandler);
try {
mOrientationListener.setCurrentRotation(windowManager.getRotation());
} catch (RemoteException ex) {
}
updateHybridLayout();
mSettingsObserver = new SettingsObserver(mHandler);
mSettingsObserver.observe();
// SystemUI reboot
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.USER_INTERFACE_STATE), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
// Return for reset triggers
if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.USER_INTERFACE_STATE, 0) == 0) {
return;
}
// Update layout
update(true);
// Reset trigger
Settings.System.putInt(mContext.getContentResolver(), Settings.System.USER_INTERFACE_STATE, 0);
}
});
// Expanded desktop
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.EXPANDED_DESKTOP_STATE), false, new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
updateHybridLayout();
update(false);
}
});
mShortcutManager = new ShortcutManager(context, mHandler);
mShortcutManager.observe();
mUiMode = context.getResources().getInteger(com.android.internal.R.integer.config_defaultUiModeType);
mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
mHomeIntent.addCategory(Intent.CATEGORY_HOME);
mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PhoneWindowManager.mBroadcastWakeLock");
mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
mLidOpenRotation = readRotation(com.android.internal.R.integer.config_lidOpenRotation);
mCarDockRotation = readRotation(com.android.internal.R.integer.config_carDockRotation);
mDeskDockRotation = readRotation(com.android.internal.R.integer.config_deskDockRotation);
mUndockedHdmiRotation = readRotation(com.android.internal.R.integer.config_undockedHdmiRotation);
mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(com.android.internal.R.bool.config_carDockEnablesAccelerometer);
mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
mLidKeyboardAccessibility = mContext.getResources().getInteger(com.android.internal.R.integer.config_lidKeyboardAccessibility);
mLidNavigationAccessibility = mContext.getResources().getInteger(com.android.internal.R.integer.config_lidNavigationAccessibility);
mLidControlsSleep = mContext.getResources().getBoolean(com.android.internal.R.bool.config_lidControlsSleep);
mHasRemovableLid = mContext.getResources().getBoolean(com.android.internal.R.bool.config_hasRemovableLid);
mDeviceHardwareKeys = mContext.getResources().getInteger(com.android.internal.R.integer.config_deviceHardwareKeys);
mHasHomeKey = ((mDeviceHardwareKeys & KEY_MASK_HOME) != 0);
mHasMenuKey = ((mDeviceHardwareKeys & KEY_MASK_MENU) != 0);
mHasAssistKey = ((mDeviceHardwareKeys & KEY_MASK_ASSIST) != 0);
mHasAppSwitchKey = ((mDeviceHardwareKeys & KEY_MASK_APP_SWITCH) != 0);
// register for dock events
IntentFilter filter = new IntentFilter();
filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
filter.addAction(Intent.ACTION_DOCK_EVENT);
Intent intent = context.registerReceiver(mDockReceiver, filter);
if (intent != null) {
// Retrieve current sticky dock event broadcast.
mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
}
// register for dream-related broadcasts
filter = new IntentFilter();
filter.addAction(Intent.ACTION_DREAMING_STARTED);
filter.addAction(Intent.ACTION_DREAMING_STOPPED);
context.registerReceiver(mDreamReceiver, filter);
// register for multiuser-relevant broadcasts
filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
context.registerReceiver(mMultiuserReceiver, filter);
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
mLongPressVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_longPressVibePattern);
mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_virtualKeyVibePattern);
mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_keyboardTapVibePattern);
mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_safeModeDisabledVibePattern);
mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_safeModeEnabledVibePattern);
mScreenshotChordEnabled = mContext.getResources().getBoolean(com.android.internal.R.bool.config_enableScreenshotChord);
mGlobalKeyManager = new GlobalKeyManager(mContext);
// Controls rotation and the like.
initializeHdmiState();
// Match current screen state.
if (mPowerManager.isScreenOn()) {
screenTurningOn(null);
} else {
screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
}
String deviceKeyHandlerLib = mContext.getResources().getString(com.android.internal.R.string.config_deviceKeyHandlerLib);
String deviceKeyHandlerClass = mContext.getResources().getString(com.android.internal.R.string.config_deviceKeyHandlerClass);
if (!deviceKeyHandlerLib.equals("") && !deviceKeyHandlerClass.equals("")) {
DexClassLoader loader = new DexClassLoader(deviceKeyHandlerLib, new ContextWrapper(mContext).getCacheDir().getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
try {
Class<?> klass = loader.loadClass(deviceKeyHandlerClass);
Constructor<?> constructor = klass.getConstructor(Context.class);
mDeviceKeyHandler = (DeviceKeyHandler) constructor.newInstance(mContext);
if (DEBUG)
Slog.d(TAG, "Device key handler loaded");
} catch (Exception e) {
Slog.w(TAG, "Could not instantiate device key handler " + deviceKeyHandlerClass + " from class " + deviceKeyHandlerLib, e);
}
}
}
use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.
the class KeyguardUpdateMonitor method watchForDeviceProvisioning.
private void watchForDeviceProvisioning() {
mDeviceProvisionedObserver = new ContentObserver(mHandler) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
mDeviceProvisioned = isDeviceProvisionedInSettingsDb();
if (mDeviceProvisioned) {
mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED));
}
if (DEBUG)
Log.d(TAG, "DEVICE_PROVISIONED state = " + mDeviceProvisioned);
}
};
mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), false, mDeviceProvisionedObserver);
// prevent a race condition between where we check the flag and where we register the
// observer by grabbing the value once again...
boolean provisioned = isDeviceProvisionedInSettingsDb();
if (provisioned != mDeviceProvisioned) {
mDeviceProvisioned = provisioned;
if (mDeviceProvisioned) {
mHandler.sendMessage(mHandler.obtainMessage(MSG_DEVICE_PROVISIONED));
}
}
}
Aggregations