當前位置: 首頁>>代碼示例>>Java>>正文


Java ContentObserver.onChange方法代碼示例

本文整理匯總了Java中android.database.ContentObserver.onChange方法的典型用法代碼示例。如果您正苦於以下問題:Java ContentObserver.onChange方法的具體用法?Java ContentObserver.onChange怎麽用?Java ContentObserver.onChange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.database.ContentObserver的用法示例。


在下文中一共展示了ContentObserver.onChange方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.database.ContentObserver; //導入方法依賴的package包/類
@Override
public void onCreate(@NonNull final LifecycleOwner owner) {
    // Set up a ContentObserver to update widgets whenever the artwork changes
    mWidgetContentObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(final boolean selfChange, final Uri uri) {
            new AppWidgetUpdateTask(mContext, false)
                    .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    };
    mContext.getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI,
            true, mWidgetContentObserver);
    mContext.getContentResolver().registerContentObserver(MuzeiContract.Sources.CONTENT_URI,
            true, mWidgetContentObserver);
    // Update the widget now that the wallpaper is active to enable the 'Next' button if supported
    mWidgetContentObserver.onChange(true);
}
 
開發者ID:romannurik,項目名稱:muzei,代碼行數:18,代碼來源:WidgetUpdater.java

示例2: testTracksTableUpdate

import android.database.ContentObserver; //導入方法依賴的package包/類
/**
 * Tests registering for tracks table update.
 */
public void testTracksTableUpdate() {

  // Register two listeners
  Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>();
  Track track = new Track();
  expect(myTracksProviderUtils.getTrack(TRACK_ID)).andStubReturn(track);
  dataSource.registerContentObserver(
      eq(TracksColumns.CONTENT_URI), capture(contentObserverCapture));
  trackDataListener1.onTrackUpdated(track);
  trackDataListener2.onTrackUpdated(track);
  replay();

  trackDataHub.start();
  trackDataHub.loadTrack(TRACK_ID);
  trackDataHub.registerTrackDataListener(
      trackDataListener1, EnumSet.of(TrackDataType.TRACKS_TABLE));
  trackDataHub.registerTrackDataListener(
      trackDataListener2, EnumSet.of(TrackDataType.TRACKS_TABLE));
  verifyAndReset();

  // Causes tracks table update
  ContentObserver contentObserver = contentObserverCapture.getValue();
  expect(myTracksProviderUtils.getTrack(TRACK_ID)).andStubReturn(track);
  trackDataListener1.onTrackUpdated(track);
  trackDataListener2.onTrackUpdated(track);
  replay();

  contentObserver.onChange(false);
  verifyAndReset();

  // Unregister one listener
  expect(myTracksProviderUtils.getTrack(TRACK_ID)).andStubReturn(track);
  trackDataListener2.onTrackUpdated(track);
  replay();

  trackDataHub.unregisterTrackDataListener(trackDataListener1);
  contentObserver.onChange(false);
  verifyAndReset();

  // Unregister the second listener
  dataSource.unregisterContentObserver(contentObserver);
  replay();

  trackDataHub.unregisterTrackDataListener(trackDataListener2);
  contentObserver.onChange(false);
  verifyAndReset();
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:51,代碼來源:TrackDataHubTest.java

示例3: testTrackPointsTableUpdate

import android.database.ContentObserver; //導入方法依賴的package包/類
/**
 * Tests track points table update.
 */
public void testTrackPointsTableUpdate() {
  // Register one listener
  Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>();
  dataSource.registerContentObserver(
      eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));

  FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
  expect(myTracksProviderUtils.getTrackPointLocationIterator(
      eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
  expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
  trackDataListener1.clearTrackPoints();
  locationIterator.expectLocationsDelivered(trackDataListener1);
  trackDataListener1.onNewTrackPointsDone();
  replay();

  trackDataHub.start();
  trackDataHub.loadTrack(TRACK_ID);
  trackDataHub.registerTrackDataListener(
      trackDataListener1, EnumSet.of(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE));
  verifyAndReset();

  // Register a second listener
  locationIterator = new FixedSizeLocationIterator(1, 10, 5);
  expect(myTracksProviderUtils.getTrackPointLocationIterator(
      eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
  expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
  trackDataListener2.clearTrackPoints();
  locationIterator.expectLocationsDelivered(trackDataListener2);
  trackDataListener2.onNewTrackPointsDone();
  replay();

  trackDataHub.registerTrackDataListener(
      trackDataListener2, EnumSet.of(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE));
  verifyAndReset();

  // Deliver more points - should go to both listeners without clearing
  ContentObserver contentObserver = contentObserverCapture.getValue();
  locationIterator = new FixedSizeLocationIterator(11, 10, 1);
  expect(myTracksProviderUtils.getTrackPointLocationIterator(
      eq(TRACK_ID), eq(11L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
  expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(20L);
  locationIterator.expectLocationsDelivered(trackDataListener1);
  locationIterator.expectLocationsDelivered(trackDataListener2);
  trackDataListener1.onNewTrackPointsDone();
  trackDataListener2.onNewTrackPointsDone();
  replay();

  contentObserver.onChange(false);
  verifyAndReset();

  // Unregister one listener and change track
  locationIterator = new FixedSizeLocationIterator(101, 10);
  expect(myTracksProviderUtils.getTrackPointLocationIterator(
      eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
      .andReturn(locationIterator);
  expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(110L);
  trackDataListener2.clearTrackPoints();
  locationIterator.expectLocationsDelivered(trackDataListener2);
  trackDataListener2.onNewTrackPointsDone();
  replay();

  trackDataHub.unregisterTrackDataListener(trackDataListener1);
  trackDataHub.loadTrack(TRACK_ID + 1);
  verifyAndReset();
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:69,代碼來源:TrackDataHubTest.java

示例4: testTrackPointsTableUpdate_resampling

import android.database.ContentObserver; //導入方法依賴的package包/類
/**
 * Tests track points table update with resampling.
 */
public void testTrackPointsTableUpdate_resampling() {
  Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
  dataSource.registerContentObserver(
      eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture));

  // Deliver 30 points (no sampling happens)
  FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 30, 5);
  expect(myTracksProviderUtils.getTrackPointLocationIterator(
      eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
  expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(30L);

  trackDataListener1.clearTrackPoints();
  locationIterator.expectLocationsDelivered(trackDataListener1);
  trackDataListener1.onNewTrackPointsDone();
  replay();

  trackDataHub.start();
  trackDataHub.loadTrack(TRACK_ID);
  trackDataHub.registerTrackDataListener(
      trackDataListener1, EnumSet.of(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE));
  verifyAndReset();

  // Now deliver 30 more (incrementally sampled)
  ContentObserver observer = observerCapture.getValue();
  locationIterator = new FixedSizeLocationIterator(31, 30);
  expect(myTracksProviderUtils.getTrackPointLocationIterator(
      eq(TRACK_ID), eq(31L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
  expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(60L);
  locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
  trackDataListener1.onNewTrackPointsDone();
  replay();

  observer.onChange(false);
  verifyAndReset();

  // Now another 30 (triggers resampling)
  locationIterator = new FixedSizeLocationIterator(1, 90);
  expect(myTracksProviderUtils.getTrackPointLocationIterator(
      eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
  expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(90L);
  trackDataListener1.clearTrackPoints();
  locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
  trackDataListener1.onNewTrackPointsDone();
  replay();

  observer.onChange(false);
  verifyAndReset();
}
 
開發者ID:Plonk42,項目名稱:mytracks,代碼行數:52,代碼來源:TrackDataHubTest.java


注:本文中的android.database.ContentObserver.onChange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。