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:edu.stanford.mobisocial.dungbeetle.feed.view.FeedBaseFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mFeedObserver = new ContentObserver(new Handler(activity.getMainLooper())) {
        @Override//from   www .  ja  v a 2  s .  co  m
        public void onChange(boolean selfChange) {
            onFeedUpdated();
        }
    };
    mFeedUri = getArguments().getParcelable(ARG_FEED_URI);
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedHeadFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mFeedObserver = new ContentObserver(new Handler(getActivity().getMainLooper())) {
        @Override/* w  w w  . j  av  a  2s . co  m*/
        public void onChange(boolean selfChange) {
            bindCurrentView();
        }
    };
    mFeedUri = getArguments().getParcelable(ARG_FEED_URI);
    ContentResolver resolver = getActivity().getContentResolver();
    resolver.registerContentObserver(mFeedUri, true, mFeedObserver);
    bindCurrentView();
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedSlideshowFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mFeedObserver = new ContentObserver(new Handler(getActivity().getMainLooper())) {
        @Override/* w  w w.jav  a  2  s .  c o m*/
        public void onChange(boolean selfChange) {
            // TODO, queue to end of list if we don't requery
        }
    };
    mFeedUri = getArguments().getParcelable(ARG_FEED_URI);
    ContentResolver resolver = getActivity().getContentResolver();
    resolver.registerContentObserver(mFeedUri, true, mFeedObserver);
    startSlideshow();
}

From source file:org.kaaproject.kaa.demo.photoframe.kaa.KaaInfoSlave.java

void initDeviceInfo(final Context context, final Runnable onAlbumListUpdated) {
    mDeviceInfo.setManufacturer(android.os.Build.MANUFACTURER);
    mDeviceInfo.setModel(android.os.Build.MODEL);
    mPlayInfo.setStatus(PlayStatus.STOPPED);

    final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    mAlbumsMap.putAll(fetchAlbums(context, uri));

    /**//from w  w w .j a  va 2s.  c  o m
     * Register content observer, to notify about updates
     */
    context.getContentResolver().registerContentObserver(uri, true, new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            super.onChange(selfChange);

            mAlbumsMap.clear();
            mAlbumsMap.putAll(fetchAlbums(context, uri));

            onAlbumListUpdated.run();
        }
    });
}

From source file:org.linkdroid.BroadcastReceiverService.java

@Override
public void onCreate() {
    super.onCreate();
    if (!Settings.isEventsEnabled(this)) {
        Log.d(TAG, "Service created but events is disabled.");
        stopSelf();/*from   w ww. j a v a 2  s.c o m*/
        return;
    }
    try {
        Log.d(TAG, "Creating service");

        LogsService.logSystemDebugMessage(this, "" + getString(R.string.broadcastreceiverservice_create));

        contentObserver = new ContentObserver(new Handler()) {
            @Override
            public void onChange(boolean selfChange) {
                super.onChange(selfChange);
                Intent i = new Intent(BroadcastReceiverService.this, BroadcastReceiverService.class);
                startService(i);
            }
        };

        intentFiltersCursor = getContentResolver().query(CONTENT_URI, null, null, null, null);
        intentFiltersCursor.registerContentObserver(contentObserver);
    } catch (Exception e) {
        LogsService.logSystemDebugMessage(this, e.toString());
    }
}

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

@AfterInject
void setMissedCallObserver() {
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        return;/*from  w  ww .  j  a v  a 2  s .  c o m*/
    }

    checkMissedCallsCount();
    final ContentObserver contentObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange) {
            checkMissedCallsCount();
        }
    };
    Log.i(TAG, "Observing missed calls.");
    contentObservers.add(contentObserver);
    getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI, true, contentObserver);
}

From source file:org.pixmob.freemobile.netstat.ui.StatisticsFragment.java

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

    if (exportTask != null) {
        exportTask.setFragmentManager(getFragmentManager());
    }//from w  w w  . j  ava  2s  .  c o  m

    // Monitor database updates: when new data is available, this fragment
    // is updated with the new values.
    contentMonitor = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange) {
            super.onChange(selfChange);

            Log.i(TAG, "Content updated: refresh statistics");
            refresh();
        }
    };

    // Get widgets.
    final Activity a = getActivity();
    statisticsGroup = a.findViewById(R.id.statistics);
    progressBar = (ProgressBar) a.findViewById(R.id.states_progress);
    mobileNetworkChart = (MobileNetworkChart) a.findViewById(R.id.mobile_network_chart);
    batteryChart = (BatteryChart) a.findViewById(R.id.battery_chart);
    onOrangeNetwork = (TextView) a.findViewById(R.id.on_orange_network);
    onFreeMobileNetwork = (TextView) a.findViewById(R.id.on_free_mobile_network);
    statMobileNetwork = (TextView) a.findViewById(R.id.stat_mobile_network);
    statMobileCode = (TextView) a.findViewById(R.id.stat_mobile_code);
    statScreenOn = (TextView) a.findViewById(R.id.stat_screen);
    statWifiOn = (TextView) a.findViewById(R.id.stat_wifi);
    statOnOrange = (TextView) a.findViewById(R.id.stat_on_orange);
    statOnFreeMobile = (TextView) a.findViewById(R.id.stat_on_free_mobile);
    statOnFemtocell = (TextView) a.findViewById(R.id.stat_on_femtocell);
    statBattery = (TextView) a.findViewById(R.id.stat_battery);

    // The fields are hidden the first time this fragment is displayed,
    // while statistics data are being loaded.
    statisticsGroup.setVisibility(View.INVISIBLE);

    setHasOptionsMenu(true);

    getLoaderManager().initLoader(0, null, this);
}

From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java

@Override
public void onCreate() {
    super.onCreate();
    mGeocoder = new Geocoder(this);
    mContentObserver = new ContentObserver(new Handler()) {
        @Override//from  w  w  w .  j a v a2s.  c  om
        public void onChange(boolean selfChange, Uri uri) {
            // Update the metadata
            updateMeta();

            // See if we've just added the very first image
            Artwork currentArtwork = getCurrentArtwork();
            if (currentArtwork == null) {
                publishNextArtwork(null);
                return;
            }

            // See if the current artwork was removed
            Cursor data = getContentResolver().query(GalleryContract.ChosenPhotos.CONTENT_URI,
                    new String[] { BaseColumns._ID }, GalleryContract.ChosenPhotos.COLUMN_NAME_URI + "=?",
                    new String[] { currentArtwork.getToken() }, null);
            if (data == null || !data.moveToFirst()) {
                // We're showing a removed URI
                publishNextArtwork(null);
            }
            if (data != null) {
                data.close();
            }
        }
    };
    // Make any changes since the last time the GalleryArtSource was created
    mContentObserver.onChange(false, GalleryContract.ChosenPhotos.CONTENT_URI);
    getContentResolver().registerContentObserver(GalleryContract.ChosenPhotos.CONTENT_URI, true,
            mContentObserver);
}

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SQLiteOpenHelper helper = App.getDatabaseSource(mActivity);
    mIdentitiesManager = new IdentitiesManager(helper);
    mId = this.getArguments().getLong(ViewProfileActivity.PROFILE_ID);

    mIdent = mIdentitiesManager.getIdentityWithThumbnailsForId(mId);

    //TODO: some of these can be "deduped" but some can't e.g. we depend on the my profile updated
    //ones to refresh the ui after a change happens.  for now, just don't leave musubi open to the profile screen
    //while your gettign a huge blast of changes
    mObserver = new ContentObserver(new Handler(mActivity.getMainLooper())) {
        @Override/*from   w  w w  . j  a va 2s.com*/
        public void onChange(boolean arg0) {
            updateDynamicElements();
        }
    };
}

From source file:de.vanita5.twittnuker.fragment.support.CursorStatusesFragment.java

@Override
public void onStart() {
    super.onStart();
    final ContentResolver cr = getContentResolver();
    mContentObserver = new ContentObserver(new Handler()) {
        @Override//w w  w . jav  a 2  s  .c  om
        public void onChange(boolean selfChange) {
            reloadStatuses();
        }
    };
    cr.registerContentObserver(Accounts.CONTENT_URI, true, mContentObserver);
}