@Test public void testSearch() throws InterruptedException { prepareLooper(); final String query = MockMediaLibraryService2.SEARCH_QUERY; final int page = 4; final int pageSize = 10; final Bundle extras = new Bundle(); extras.putString(TAG, TAG); final CountDownLatch latchForSearch = new CountDownLatch(1); final CountDownLatch latchForGetSearchResult = new CountDownLatch(1); final BrowserCallback callback = new BrowserCallback() { @Override public void onSearchResultChanged(MediaBrowser2 browser, String queryOut, int itemCount, Bundle extrasOut) { assertEquals(query, queryOut); assertTrue(TestUtils.equals(extras, extrasOut)); assertEquals(MockMediaLibraryService2.SEARCH_RESULT_COUNT, itemCount); latchForSearch.countDown(); } @Override public void onGetSearchResultDone(MediaBrowser2 browser, String queryOut, int pageOut, int pageSizeOut, List<MediaItem2> result, Bundle extrasOut) { assertEquals(query, queryOut); assertEquals(page, pageOut); assertEquals(pageSize, pageSizeOut); assertTrue(TestUtils.equals(extras, extrasOut)); assertNotNull(result); int fromIndex = (page - 1) * pageSize; int toIndex = Math.min( page * pageSize, MockMediaLibraryService2.SEARCH_RESULT_COUNT); for (int originalIndex = fromIndex; originalIndex < toIndex; originalIndex++) { int relativeIndex = originalIndex - fromIndex; Assert.assertEquals( MockMediaLibraryService2.SEARCH_RESULT.get(originalIndex).getMediaId(), result.get(relativeIndex).getMediaId()); } latchForGetSearchResult.countDown(); } }; final SessionToken2 token = MockMediaLibraryService2.getToken(mContext); MediaBrowser2 browser = (MediaBrowser2) createController(token, true, callback); browser.search(query, extras); assertTrue(latchForSearch.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); browser.getSearchResult(query, page, pageSize, extras); assertTrue(latchForGetSearchResult.await(WAIT_TIME_MS, TimeUnit.MILLISECONDS)); }
public void search(@NonNull String query, @Nullable Bundle extras) { MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } browser.search(query, extras, new MediaBrowserCompat.SearchCallback() { @Override public void onSearchResult(final String query, final Bundle extras, final List<MediaItem> items) { getCallbackExecutor().execute(new Runnable() { @Override public void run() { getCallback().onSearchResultChanged( MediaBrowser2.this, query, items.size(), extras); } }); } @Override public void onError(final String query, final Bundle extras) { } }); }
MediaBrowser2 extends MediaController2 { public void search(@NonNull String query, @Nullable Bundle extras) { MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } browser.search(query, extras, new MediaBrowserCompat.SearchCallback() { @Override public void onSearchResult(final String query, final Bundle extras, final List<MediaItem> items) { getCallbackExecutor().execute(new Runnable() { @Override public void run() { getCallback().onSearchResultChanged( MediaBrowser2.this, query, items.size(), extras); } }); } @Override public void onError(final String query, final Bundle extras) { } }); } }
MediaBrowser2 extends MediaController2 { public void search(@NonNull String query, @Nullable Bundle extras) { MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } browser.search(query, extras, new MediaBrowserCompat.SearchCallback() { @Override public void onSearchResult(final String query, final Bundle extras, final List<MediaItem> items) { getCallbackExecutor().execute(new Runnable() { @Override public void run() { getCallback().onSearchResultChanged( MediaBrowser2.this, query, items.size(), extras); } }); } @Override public void onError(final String query, final Bundle extras) { } }); } MediaBrowser2(@NonNull Context context, @NonNull SessionToken2 token,
            @NonNull /*@CallbackExecutor*/ Executor executor, @NonNull BrowserCallback callback); }
MediaBrowser2 extends MediaController2 { public void search(@NonNull String query, @Nullable Bundle extras) { MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } browser.search(query, extras, new MediaBrowserCompat.SearchCallback() { @Override public void onSearchResult(final String query, final Bundle extras, final List<MediaItem> items) { getCallbackExecutor().execute(new Runnable() { @Override public void run() { getCallback().onSearchResultChanged( MediaBrowser2.this, query, items.size(), extras); } }); } @Override public void onError(final String query, final Bundle extras) { } }); } MediaBrowser2(@NonNull Context context, @NonNull SessionToken2 token,
            @NonNull /*@CallbackExecutor*/ Executor executor, @NonNull BrowserCallback callback); @Override void close(); void getLibraryRoot(@Nullable final Bundle extras); void subscribe(@NonNull String parentId, @Nullable Bundle extras); void unsubscribe(@NonNull String parentId); void getChildren(@NonNull String parentId, int page, int pageSize,
            @Nullable Bundle extras); void getItem(@NonNull final String mediaId); void search(@NonNull String query, @Nullable Bundle extras); void getSearchResult(final @NonNull String query, final int page, final int pageSize,
            final @Nullable Bundle extras); }
MediaBrowser2 extends MediaController2 { public void search(@NonNull String query, @Nullable Bundle extras) { MediaBrowserCompat browser = getBrowserCompat(); if (browser == null) { return; } browser.search(query, extras, new MediaBrowserCompat.SearchCallback() { @Override public void onSearchResult(final String query, final Bundle extras, final List<MediaItem> items) { getCallbackExecutor().execute(new Runnable() { @Override public void run() { getCallback().onSearchResultChanged( MediaBrowser2.this, query, items.size(), extras); } }); } @Override public void onError(final String query, final Bundle extras) { } }); } MediaBrowser2(@NonNull Context context, @NonNull SessionToken2 token,
            @NonNull /*@CallbackExecutor*/ Executor executor, @NonNull BrowserCallback callback); @Override void close(); void getLibraryRoot(@Nullable final Bundle extras); void subscribe(@NonNull String parentId, @Nullable Bundle extras); void unsubscribe(@NonNull String parentId); void getChildren(@NonNull String parentId, int page, int pageSize,
            @Nullable Bundle extras); void getItem(@NonNull final String mediaId); void search(@NonNull String query, @Nullable Bundle extras); void getSearchResult(final @NonNull String query, final int page, final int pageSize,
            final @Nullable Bundle extras); @RestrictTo(LIBRARY_GROUP)
    static final String EXTRA_ITEM_COUNT; @RestrictTo(LIBRARY_GROUP)
    static final String MEDIA_BROWSER2_SUBSCRIBE; }