Example usage for android.database ContentObserver ContentObserver

List of usage examples for android.database ContentObserver ContentObserver

Introduction

In this page you can find the example usage for android.database ContentObserver ContentObserver.

Prototype

public ContentObserver(Handler handler) 

Source Link

Document

Creates a content observer.

Usage

From source file:com.wolkabout.hexiwear.service.NotificationService.java

@AfterInject
void setUnreadMessageObserver() {
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        return;//  w ww  .j  ava  2  s.co m
    }

    checkUnreadMessageCount();
    final ContentObserver contentObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange) {
            checkUnreadMessageCount();
        }
    };
    Log.i(TAG, "Observing unread messages.");
    contentObservers.add(contentObserver);
    getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, contentObserver);
}

From source file:mobisocial.socialkit.musubi.Musubi.java

public Musubi(Context context) {
    mContext = context.getApplicationContext();
    if (context instanceof Activity) {
        setDataFromIntent(((Activity) context).getIntent());
    }/*from   w  ww  . j a  va  2s.com*/
    mContentProviderThread = new ContentProviderThread();
    mContentProviderThread.start();
    if (mContentProviderThread.mHandler == null) {
        synchronized (this) {
            while (mContentProviderThread.mHandler == null) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    continue;
                }
            }
        }
    }

    mContactUpdateObserver = new ContentObserver(mContentProviderThread.mHandler) {
        @Override
        public void onChange(boolean selfChange) {
            sUserCache.clear();
        }
    };
    mContext.getContentResolver().registerContentObserver(CONTACTS_URI, true, mContactUpdateObserver);
}

From source file:dev.drsoran.moloko.fragments.TaskEditFragment.java

private void registerForTaskDeletedByBackgroundSync() {
    taskChangesObserver = new ContentObserver(MolokoApp.getHandler()) {
        @Override//from   w w w.ja v a 2  s .c  o m
        public void onChange(boolean selfChange) {
            getSherlockActivity().getSupportLoaderManager().initLoader(TaskLoader.ID, Bundle.EMPTY,
                    TaskEditFragment.this.taskLoaderHandler);
        }
    };

    getSherlockActivity().getContentResolver().registerContentObserver(
            Queries.contentUriWithId(RawTasks.CONTENT_URI, getTaskAssertNotNull().getId()), false,
            taskChangesObserver);
}

From source file:mobisocial.musubi.ui.fragments.ContactsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mObserver = new LessSpammyContentObserver(new Handler(mActivity.getMainLooper())) {
        @Override// w w  w  . ja  va  2 s  .com
        public void lessSpammyOnChange(boolean arg0) {
            if (mContacts == null || mContacts.getCursor() == null || !isAdded())
                return;
            mContacts.getCursor().requery();
        }
    };
    mEditableObserver = new ContentObserver(new Handler(mActivity.getMainLooper())) {
        @Override
        public void onChange(boolean arg0) {
            if (mContacts == null || mContacts.getCursor() == null || !isAdded())
                return;
            mContacts.getCursor().requery();
        }
    };
}

From source file:com.google.android.apps.muzei.MuzeiWallpaperService.java

private void initialize() {
    FirebaseAnalytics.getInstance(this).setUserProperty("device_type", BuildConfig.DEVICE_TYPE);
    SourceManager.subscribeToSelectedSource(MuzeiWallpaperService.this);
    mNetworkChangeReceiver = new NetworkChangeReceiver();
    IntentFilter networkChangeFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mNetworkChangeReceiver, networkChangeFilter);
    // Ensure we retry loading the artwork if the network changed while the wallpaper was disabled
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    Intent retryIntent = TaskQueueService.maybeRetryDownloadDueToGainedConnectivity(this);
    if (retryIntent != null && connectivityManager.getActiveNetworkInfo() != null
            && connectivityManager.getActiveNetworkInfo().isConnected()) {
        startService(retryIntent);//from   w w w .jav a 2 s  .  c  o  m
    }

    // Set up a thread to update notifications whenever the artwork changes
    mNotificationHandlerThread = new HandlerThread("MuzeiWallpaperService-Notification");
    mNotificationHandlerThread.start();
    mNotificationContentObserver = new ContentObserver(new Handler(mNotificationHandlerThread.getLooper())) {
        @Override
        public void onChange(final boolean selfChange, final Uri uri) {
            NewWallpaperNotificationReceiver.maybeShowNewArtworkNotification(MuzeiWallpaperService.this);
        }
    };
    getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true,
            mNotificationContentObserver);

    // Set up a thread to update Android Wear whenever the artwork changes
    mWearableHandlerThread = new HandlerThread("MuzeiWallpaperService-Wearable");
    mWearableHandlerThread.start();
    mWearableContentObserver = new ContentObserver(new Handler(mWearableHandlerThread.getLooper())) {
        @Override
        public void onChange(final boolean selfChange, final Uri uri) {
            WearableController.updateArtwork(MuzeiWallpaperService.this);
        }
    };
    getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true,
            mWearableContentObserver);

    // Set up a thread to update the Artwork Info shortcut whenever the artwork changes
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        mArtworkInfoShortcutHandlerThread = new HandlerThread("MuzeiWallpaperService-ArtworkInfoShortcut");
        mArtworkInfoShortcutHandlerThread.start();
        mArtworkInfoShortcutContentObserver = new ContentObserver(
                new Handler(mArtworkInfoShortcutHandlerThread.getLooper())) {
            @RequiresApi(api = Build.VERSION_CODES.N_MR1)
            @Override
            public void onChange(final boolean selfChange, final Uri uri) {
                ArtworkInfoShortcutController.updateShortcut(MuzeiWallpaperService.this);
            }
        };
        getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true,
                mArtworkInfoShortcutContentObserver);
    }
    mInitialized = true;
}

From source file:org.mozilla.gecko.Tab.java

public Tab(int id, String url, boolean external, int parentId, String title) {
    mId = id;/*from  ww w. j  ava2  s .c  o  m*/
    mUrl = url;
    mExternal = external;
    mParentId = parentId;
    mTitle = title;
    mFavicon = null;
    mFaviconUrl = null;
    mSecurityMode = "unknown";
    mThumbnail = null;
    mHistory = new ArrayList<HistoryEntry>();
    mHistoryIndex = -1;
    mBookmark = false;
    mDoorHangers = new HashMap<String, DoorHanger>();
    mFaviconLoadId = 0;
    mDocumentURI = "";
    mContentType = "";
    mPluginViews = new ArrayList<View>();
    mPluginLayers = new HashMap<Surface, Layer>();
    mHasLoaded = false;
    mContentResolver = Tabs.getInstance().getContentResolver();
    mContentObserver = new ContentObserver(GeckoAppShell.getHandler()) {
        public void onChange(boolean selfChange) {
            updateBookmark();
        }
    };
    BrowserDB.registerBookmarkObserver(mContentResolver, mContentObserver);
}

From source file:org.getlantern.firetweet.fragment.support.CursorStatusesFragment.java

@Override
public void onStart() {
    super.onStart();
    final ContentResolver cr = getContentResolver();
    mContentObserver = new ContentObserver(new Handler()) {
        @Override/* w  ww.j ava2 s. c  o  m*/
        public void onChange(boolean selfChange) {
            reloadStatuses();
        }
    };
    cr.registerContentObserver(Accounts.CONTENT_URI, true, mContentObserver);
    updateRefreshState();
}

From source file:com.wolkabout.hexiwear.service.NotificationService.java

@AfterInject
void setUnreadEmailsObserver() {
    final Account[] accounts = AccountManager.get(this).getAccounts();
    for (final Account account : accounts) {
        unreadEmailCounts.put(account.name, -1);
        checkUnreadEmailCount(account);/*  w ww.  ja v  a  2 s . co m*/
        final ContentObserver contentObserver = new ContentObserver(new Handler()) {
            public void onChange(boolean selfChange) {
                checkUnreadEmailCount(account);
            }
        };
        Log.i(TAG, "Observing unread emails for " + account.name);
        contentObservers.add(contentObserver);
        getContentResolver().registerContentObserver(getEmailQuery(account), true, contentObserver);
    }
}

From source file:org.openbmap.activities.SessionListFragment.java

/**
 * @link http://stackoverflow.com/questions/6317767/cant-add-a-headerview-to-a-listfragment
 *      Fragment lifecycle/* w  w w.j av a  2 s  . c o  m*/
 *      onAttach(Activity) called once the fragment is associated with its activity.
 *      onCreate(Bundle) called to do initial creation of the fragment.
 *      onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view hierarchy associated with the fragment.
 *      onActivityCreated(Bundle) tells the fragment that its activity has completed its own Activity.onCreate.
 *      onStart() makes the fragment visible to the user (based on its containing activity being started).
 *      onResume() makes the fragment interacting with the user (based on its containing activity being resumed).
 */

@Override
public final void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final String[] from = new String[] { Schema.COL_ID, Schema.COL_CREATED_AT, Schema.COL_IS_ACTIVE,
            Schema.COL_HAS_BEEN_EXPORTED, Schema.COL_NUMBER_OF_CELLS, Schema.COL_NUMBER_OF_WIFIS };

    final int[] to = new int[] { R.id.sessionlistfragment_id, R.id.sessionlistfragment_created_at,
            R.id.sessionlistfragment_statusicon, R.id.sessionlistfragment_uploadicon,
            R.id.sessionlistfragment_no_cells, R.id.sessionlistfragment_no_wifis };

    mAdapter = new SimpleCursorAdapter(getActivity().getBaseContext(), R.layout.sessionlistfragment, null, from,
            to, 0);
    mAdapter.setViewBinder(new SessionViewBinder());

    // Trying to add a Header View.
    final View header = (View) getLayoutInflater(savedInstanceState).inflate(R.layout.sessionlistheader, null);
    this.getListView().addHeaderView(header);

    // setup data adapters
    setListAdapter(mAdapter);
    getActivity().getSupportLoaderManager().initLoader(0, null, this);

    // register for change notifications
    mObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(final boolean selfChange) {
            refreshAdapter();
        };
    };

    getListView().setLongClickable(true);
    getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    getListView().setOnItemLongClickListener(new ActionModeUtils((ActionBarActivity) this.getActivity(),
            R.menu.session_context, this, getListView()));
}

From source file:mobisocial.musubi.service.AddressBookUpdateHandler.java

public AddressBookUpdateHandler(Context context, SQLiteOpenHelper dbh, HandlerThread thread,
        ContentResolver resolver) {//from  ww  w  .  j  a va2  s .  co  m
    super(new Handler(thread.getLooper()));
    mThread = thread;
    mContext = context.getApplicationContext();
    mContactThumbnailCache = App.getContactCache(context);
    mAccountType = mContext.getString(R.string.account_type);

    resolver.registerContentObserver(MusubiService.FORCE_RESCAN_CONTACTS, false,
            new ContentObserver(new Handler(thread.getLooper())) {
                public void onChange(boolean selfChange) {
                    mLastRun = -1;
                    AddressBookUpdateHandler.this.dispatchChange(false);
                }
            });

    dispatchChange(false);
}