当前位置: 首页>>代码示例>>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;未经允许,请勿转载。