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.bitants.wally.fragments.SavedImagesFragment.java

private void initObserver(Cursor cursor) {
    if (cursor != null) {
        if (contentObserver == null) {
            contentObserver = new ContentObserver(uiHandler) {
                @Override// w w w  .jav  a2s  . co  m
                public void onChange(boolean selfChange) {
                    super.onChange(selfChange);
                    getImages(0, null);
                }
            };

        }
        try {
            cursor.registerContentObserver(contentObserver);
        } catch (IllegalStateException e) {
            //Oh goodie, it's already registered. Nevermind then.
        }
    }
}

From source file:com.g11x.checklistapp.ChecklistActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (checklistContentObserver != null) {
        getContentResolver().unregisterContentObserver(checklistContentObserver);
    }/*  w ww . j  a v  a2 s  .c om*/
    checklistContentObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            getSupportLoaderManager().restartLoader(LOADER_ID, null, ChecklistActivity.this);
            super.onChange(selfChange);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            getSupportLoaderManager().restartLoader(LOADER_ID, null, ChecklistActivity.this);
            super.onChange(selfChange, uri);
        }
    };
    getContentResolver().registerContentObserver(Database.ChecklistItem.CONTENT_URI, true,
            checklistContentObserver);

    return new CursorLoader(ChecklistActivity.this, Database.ChecklistItem.CONTENT_URI,
            ChecklistItem.PROJECTION, null, null, null);
}

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

private void registerForNoteDeletedByBackgroundSync() {
    noteChangesObserver = new ContentObserver(MolokoApp.getHandler()) {
        @Override//from  w ww. j a v a  2 s  .  c  o  m
        public void onChange(boolean selfChange) {
            getSherlockActivity().getSupportLoaderManager().initLoader(RtmTaskNoteLoader.ID, Bundle.EMPTY,
                    NoteEditFragment.this);
        }
    };

    getSherlockActivity().getContentResolver().registerContentObserver(
            Queries.contentUriWithId(Notes.CONTENT_URI, getNoteAssertNotNull().getId()), false,
            noteChangesObserver);
}

From source file:org.mariotaku.twidere.fragment.CursorActivitiesFragment.java

@Override
public void onStart() {
    super.onStart();
    final ContentResolver cr = getContentResolver();
    mContentObserver = new ContentObserver(new Handler()) {
        @Override/*from  www .  jav  a  2s . com*/
        public void onChange(boolean selfChange) {
            reloadActivities();
        }
    };
    cr.registerContentObserver(Accounts.CONTENT_URI, true, mContentObserver);
    cr.registerContentObserver(Filters.CONTENT_URI, true, mContentObserver);
    updateRefreshState();
    reloadActivities();
}

From source file:org.kontalk.data.Contact.java

public static void init(Context context, Handler handler) {
    context.getContentResolver().registerContentObserver(Contacts.CONTENT_URI, false,
            new ContentObserver(handler) {
                @Override//w  ww . ja va  2 s .  c  om
                public void onChange(boolean selfChange) {
                    invalidate();
                }
            });
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (DBG)//  w  w w  .  ja  va  2  s .c  om
        Log.d(TAG, "Creating new FeedListFragment");

    mFeeds = new FeedListAdapter(mActivity);
    for (int i = 0; i < DAYS_TO_SHOW + 1; i++) {
        mFeeds.addPartition(false, true);
    }
    setListAdapter(mFeeds);

    mObserver = new ContentObserver(new Handler(mActivity.getMainLooper())) {
        @Override
        public void onChange(boolean arg0) {
            if (mFeeds.isEmpty() || !isAdded()) {
                return;
            }
            initLoaders(true);
        }
    };
}

From source file:com.g11x.checklistapp.ChecklistItemActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (checklistContentObserver != null) {
        getContentResolver().unregisterContentObserver(checklistContentObserver);
    }// w  w w  .  jav a  2 s .c  o  m
    checklistContentObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            getSupportLoaderManager().restartLoader(LOADER_ID, null, ChecklistItemActivity.this);
            super.onChange(selfChange);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            getSupportLoaderManager().restartLoader(LOADER_ID, null, ChecklistItemActivity.this);
            super.onChange(selfChange, uri);
        }
    };
    getContentResolver().registerContentObserver(Database.ChecklistItem.CONTENT_URI, true,
            checklistContentObserver);

    return new CursorLoader(ChecklistItemActivity.this, Database.ChecklistItem.CONTENT_URI,
            ChecklistItem.PROJECTION, null, null, null);
}

From source file:com.adkdevelopment.earthquakesurvival.ui.PagerActivity.java

/**
 * The {@link ViewPager} that will host the section contents.
 *//*ww w . j  a v a 2 s  .c  om*/

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pager_activity);

    _rxBus = App.getRxBusSingleton();

    mGeofenceList = new ArrayList<>();

    ButterKnife.bind(this);

    setSupportActionBar(mToolbar);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mPagerAdapter = new PagerAdapter(getSupportFragmentManager(), getApplicationContext());

    // Set up the ViewPager with the sections adapter.
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOffscreenPageLimit(mPagerAdapter.getCount());
    mViewPager.setPageTransformer(true, new ZoomOutPageTransformer());
    mTab.setupWithViewPager(mViewPager);
    setTabImages();

    // start SyncAdapter
    SyncAdapter.initializeSyncAdapter(this);

    loadPermissions(Manifest.permission.ACCESS_FINE_LOCATION, REQUEST_FINE_LOCATION);

    if (Utilities.checkPlayServices(this)) {
        // Set up GoogleApiClient
        mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API)
                .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    }

    // Observe SyncAdapter work and update Geofences
    mObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
        public void onChange(boolean selfChange) {
            populateGeofenceList();
            observeGeofences();
        }
    };
    getContentResolver().registerContentObserver(EarthquakeColumns.CONTENT_URI, false, mObserver);
}

From source file:com.appsimobile.appsii.SidebarHotspot.java

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mSwipeInProgress = false;//from w  w  w.  j  a va  2 s.com

    if (mHotspotsPagesObserver == null) {
        mHotspotsPagesObserver = new ContentObserver(mHandler) {
            @Override
            public void onChange(boolean selfChange) {
                onChange(selfChange, null);
            }

            @Override
            public void onChange(boolean selfChange, Uri uri) {
                reloadHotspotData();
            }
        };
        getContext().getContentResolver().registerContentObserver(HomeContract.HotspotPages.CONTENT_URI, true,
                mHotspotsPagesObserver);
    }

    setupBackground();
}

From source file:org.thoughtcrime.SMP.ConversationListActivity.java

private void initializeContactUpdatesReceiver() {
    observer = new ContentObserver(null) {
        @Override//from w w w.  ja va2s  .  com
        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);
}