Search in sources :

Example 1 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class NavigationBarView method getIcons.

private void getIcons(Resources res) {
    mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
    mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land);
    mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
    mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
    mRecentsIcon = res.getDrawable(R.drawable.ic_sysbar_recent);
    mRecentsLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_land);
    mRecentsAltIcon = res.getDrawable(R.drawable.ic_sysbar_recent_clear);
    mRecentsAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_clear_land);
    // Only watch for per app color changes when the setting is in check
    if (ColorUtils.getPerAppColorState(mContext)) {
        // Reset all colors
        mCurrentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mCurrentCanvas = new Canvas(mCurrentBitmap);
        mCurrentCanvas.drawColor(0xFF000000);
        mCurrentBitmapDrawable = new BitmapDrawable(mCurrentBitmap);
        mNewBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mNewCanvas = new Canvas(mNewBitmap);
        mNewCanvas.drawColor(0xFF000000);
        mNewBitmapDrawable = new BitmapDrawable(mNewBitmap);
        mTransition = new TransitionDrawable(new Drawable[] { mCurrentBitmapDrawable, mNewBitmapDrawable });
        setBackground(mTransition);
        mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.NAV_BAR_COLOR);
        updateColor();
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.NAV_BAR_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateColor();
            }
        });
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Handler(android.os.Handler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ContentObserver(android.database.ContentObserver)

Example 2 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class VibratorService method systemReady.

public void systemReady() {
    mIm = (InputManager) mContext.getSystemService(Context.INPUT_SERVICE);
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES), true, new ContentObserver(mH) {

        @Override
        public void onChange(boolean selfChange) {
            updateInputDeviceVibrators();
        }
    }, UserHandle.USER_ALL);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            updateInputDeviceVibrators();
        }
    }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mH);
    updateInputDeviceVibrators();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) ContentObserver(android.database.ContentObserver)

Example 3 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class WifiController method registerForWifiIdleTimeChange.

/**
     * Observes settings changes to scan always mode.
     */
private void registerForWifiIdleTimeChange(Handler handler) {
    ContentObserver contentObserver = new ContentObserver(handler) {

        @Override
        public void onChange(boolean selfChange) {
            readWifiIdleTime();
        }
    };
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.WIFI_IDLE_MS), false, contentObserver);
}
Also used : ContentObserver(android.database.ContentObserver)

Example 4 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

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;
    }
}
Also used : Handler(android.os.Handler) ContentObserver(android.database.ContentObserver)

Example 5 with ContentObserver

use of android.database.ContentObserver in project android_frameworks_base by ParanoidAndroid.

the class BaseStatusBar method start.

public void start() {
    mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    mWindowManagerService = WindowManagerGlobal.getWindowManagerService();
    mDisplay = mWindowManager.getDefaultDisplay();
    // set up
    mProvisioningObserver.onChange(false);
    mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, mProvisioningObserver);
    mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
    mStatusBarContainer = new FrameLayout(mContext);
    mLocale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtils.getLayoutDirectionFromLocale(mLocale);
    // Connect in to the status bar manager service
    StatusBarIconList iconList = new StatusBarIconList();
    ArrayList<IBinder> notificationKeys = new ArrayList<IBinder>();
    ArrayList<StatusBarNotification> notifications = new ArrayList<StatusBarNotification>();
    mCommandQueue = new CommandQueue(this, iconList);
    int[] switches = new int[7];
    ArrayList<IBinder> binders = new ArrayList<IBinder>();
    try {
        mBarService.registerStatusBar(mCommandQueue, iconList, notificationKeys, notifications, switches, binders);
    } catch (RemoteException ex) {
    // If the system process isn't there we're doomed anyway.
    }
    mHaloActive = Settings.System.getInt(mContext.getContentResolver(), Settings.System.HALO_ACTIVE, 0) == 1;
    createAndAddWindows();
    disable(switches[0]);
    setSystemUiVisibility(switches[1], 0xffffffff);
    topAppWindowChanged(switches[2] != 0);
    // StatusBarManagerService has a back up of IME token and it's restored here.
    setImeWindowStatus(binders.get(0), switches[3], switches[4]);
    setHardKeyboardStatus(switches[5] != 0, switches[6] != 0);
    // Set up the initial icon state
    int N = iconList.size();
    int viewIndex = 0;
    for (int i = 0; i < N; i++) {
        StatusBarIcon icon = iconList.getIcon(i);
        if (icon != null) {
            addIcon(iconList.getSlot(i), i, viewIndex, icon);
            viewIndex++;
        }
    }
    // Set up the initial notification state
    N = notificationKeys.size();
    if (N == notifications.size()) {
        for (int i = 0; i < N; i++) {
            addNotification(notificationKeys.get(i), notifications.get(i));
        }
    } else {
        Log.wtf(TAG, "Notification list length mismatch: keys=" + N + " notifications=" + notifications.size());
    }
    if (DEBUG) {
        Slog.d(TAG, String.format("init: icons=%d disabled=0x%08x lights=0x%08x menu=0x%08x imeButton=0x%08x", iconList.size(), switches[0], switches[1], switches[2], switches[3]));
    }
    mCurrentUserId = ActivityManager.getCurrentUser();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_USER_SWITCHED);
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                if (true)
                    Slog.v(TAG, "userId " + mCurrentUserId + " is in the house");
                userSwitched(mCurrentUserId);
            }
        }
    }, filter);
    // Only watch for per app color changes when the setting is in check
    if (ColorUtils.getPerAppColorState(mContext)) {
        // Reset all colors
        Bitmap currentBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mCurrentCanvas = new Canvas(currentBitmap);
        mCurrentCanvas.drawColor(0xFF000000);
        BitmapDrawable currentBitmapDrawable = new BitmapDrawable(currentBitmap);
        Bitmap newBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        mNewCanvas = new Canvas(newBitmap);
        mNewCanvas.drawColor(0xFF000000);
        BitmapDrawable newBitmapDrawable = new BitmapDrawable(newBitmap);
        mTransition = new TransitionDrawable(new Drawable[] { currentBitmapDrawable, newBitmapDrawable });
        mBarView.setBackground(mTransition);
        mLastIconColor = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
        mLastBackgroundColor = ColorUtils.getColorSettingInfo(mContext, ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR);
        updateIconColor();
        updateBackgroundColor();
        // Listen for status bar icon color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.STATUS_ICON_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateIconColor();
            }
        });
        // Listen for status bar background color changes
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(ExtendedPropertiesUtils.isTablet() ? Settings.System.NAV_BAR_COLOR : Settings.System.STATUS_BAR_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                updateBackgroundColor();
            }
        });
        // Listen for per-app-color state changes, this one will revert to stock colors all over
        mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PER_APP_COLOR), false, new ContentObserver(new Handler()) {

            @Override
            public void onChange(boolean selfChange) {
                if (!ColorUtils.getPerAppColorState(mContext)) {
                    for (int i = 0; i < ExtendedPropertiesUtils.PARANOID_COLORS_COUNT; i++) {
                        ColorUtils.ColorSettingInfo colorInfo = ColorUtils.getColorSettingInfo(mContext, Settings.System.STATUS_ICON_COLOR);
                        ColorUtils.setColor(mContext, ExtendedPropertiesUtils.PARANOID_COLORS_SETTINGS[i], colorInfo.systemColorString, "NULL", 1, 250);
                    }
                }
            }
        });
    }
    attachPie();
    // Listen for PIE gravity
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.PIE_GRAVITY), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updatePieControls();
        }
    });
    // Listen for HALO state
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_ACTIVE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            updateHalo();
        }
    });
    mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.HALO_SIZE), false, new ContentObserver(new Handler()) {

        @Override
        public void onChange(boolean selfChange) {
            restartHalo();
        }
    });
    updateHalo();
    SettingsObserver settingsObserver = new SettingsObserver(new Handler());
    settingsObserver.observe();
}
Also used : ArrayList(java.util.ArrayList) IBinder(android.os.IBinder) Bitmap(android.graphics.Bitmap) StatusBarNotification(android.service.notification.StatusBarNotification) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) ContentObserver(android.database.ContentObserver) Context(android.content.Context) IntentFilter(android.content.IntentFilter) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StatusBarIconList(com.android.internal.statusbar.StatusBarIconList) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BroadcastReceiver(android.content.BroadcastReceiver) Paint(android.graphics.Paint) FrameLayout(android.widget.FrameLayout) RemoteException(android.os.RemoteException)

Aggregations

ContentObserver (android.database.ContentObserver)120 Uri (android.net.Uri)49 Handler (android.os.Handler)49 ContentResolver (android.content.ContentResolver)38 Test (org.junit.Test)22 IntentFilter (android.content.IntentFilter)17 Intent (android.content.Intent)16 HashSet (java.util.HashSet)12 Mockito.doAnswer (org.mockito.Mockito.doAnswer)12 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 Answer (org.mockito.stubbing.Answer)12 Context (android.content.Context)11 BroadcastReceiver (android.content.BroadcastReceiver)9 PendingIntent (android.app.PendingIntent)7 RemoteException (android.os.RemoteException)7 AppOpsManager (android.app.AppOpsManager)6 Cursor (android.database.Cursor)6 GeofenceManager (com.android.server.location.GeofenceManager)6 LocationBlacklist (com.android.server.location.LocationBlacklist)6 LocationFudger (com.android.server.location.LocationFudger)6