Loading media/java/android/media/browse/MediaBrowserUtils.java +28 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package android.media.browse; import android.os.Bundle; import java.util.Collections; import java.util.List; /** * @hide */ Loading Loading @@ -75,4 +78,29 @@ public class MediaBrowserUtils { } return false; } /** * Returns a paged version of the given {@code list}, using the paging parameters in {@code * options}. */ public static List<MediaBrowser.MediaItem> applyPagingOptions( List<MediaBrowser.MediaItem> list, final Bundle options) { if (list == null) { return null; } int page = options.getInt(MediaBrowser.EXTRA_PAGE, -1); int pageSize = options.getInt(MediaBrowser.EXTRA_PAGE_SIZE, -1); if (page == -1 && pageSize == -1) { return list; } int fromIndex = pageSize * page; int toIndex = fromIndex + pageSize; if (page < 0 || pageSize < 1 || fromIndex >= list.size()) { return Collections.EMPTY_LIST; } if (toIndex > list.size()) { toIndex = list.size(); } return list.subList(fromIndex, toIndex); } } media/java/android/service/media/MediaBrowserService.java +1 −23 Original line number Diff line number Diff line Loading @@ -48,7 +48,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; Loading Loading @@ -728,7 +727,7 @@ public abstract class MediaBrowserService extends Service { List<MediaBrowser.MediaItem> filteredList = (flag & RESULT_FLAG_OPTION_NOT_HANDLED) != 0 ? applyOptions(list, options) : list; ? MediaBrowserUtils.applyPagingOptions(list, options) : list; final ParceledListSlice<MediaBrowser.MediaItem> pls; if (filteredList == null) { pls = null; Loading Loading @@ -762,27 +761,6 @@ public abstract class MediaBrowserService extends Service { } } private List<MediaBrowser.MediaItem> applyOptions(List<MediaBrowser.MediaItem> list, final Bundle options) { if (list == null) { return null; } int page = options.getInt(MediaBrowser.EXTRA_PAGE, -1); int pageSize = options.getInt(MediaBrowser.EXTRA_PAGE_SIZE, -1); if (page == -1 && pageSize == -1) { return list; } int fromIndex = pageSize * page; int toIndex = fromIndex + pageSize; if (page < 0 || pageSize < 1 || fromIndex >= list.size()) { return Collections.EMPTY_LIST; } if (toIndex > list.size()) { toIndex = list.size(); } return list.subList(fromIndex, toIndex); } private void performLoadItem(String itemId, final ConnectionRecord connection, final ResultReceiver receiver) { final Result<MediaBrowser.MediaItem> result = Loading Loading
media/java/android/media/browse/MediaBrowserUtils.java +28 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package android.media.browse; import android.os.Bundle; import java.util.Collections; import java.util.List; /** * @hide */ Loading Loading @@ -75,4 +78,29 @@ public class MediaBrowserUtils { } return false; } /** * Returns a paged version of the given {@code list}, using the paging parameters in {@code * options}. */ public static List<MediaBrowser.MediaItem> applyPagingOptions( List<MediaBrowser.MediaItem> list, final Bundle options) { if (list == null) { return null; } int page = options.getInt(MediaBrowser.EXTRA_PAGE, -1); int pageSize = options.getInt(MediaBrowser.EXTRA_PAGE_SIZE, -1); if (page == -1 && pageSize == -1) { return list; } int fromIndex = pageSize * page; int toIndex = fromIndex + pageSize; if (page < 0 || pageSize < 1 || fromIndex >= list.size()) { return Collections.EMPTY_LIST; } if (toIndex > list.size()) { toIndex = list.size(); } return list.subList(fromIndex, toIndex); } }
media/java/android/service/media/MediaBrowserService.java +1 −23 Original line number Diff line number Diff line Loading @@ -48,7 +48,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; Loading Loading @@ -728,7 +727,7 @@ public abstract class MediaBrowserService extends Service { List<MediaBrowser.MediaItem> filteredList = (flag & RESULT_FLAG_OPTION_NOT_HANDLED) != 0 ? applyOptions(list, options) : list; ? MediaBrowserUtils.applyPagingOptions(list, options) : list; final ParceledListSlice<MediaBrowser.MediaItem> pls; if (filteredList == null) { pls = null; Loading Loading @@ -762,27 +761,6 @@ public abstract class MediaBrowserService extends Service { } } private List<MediaBrowser.MediaItem> applyOptions(List<MediaBrowser.MediaItem> list, final Bundle options) { if (list == null) { return null; } int page = options.getInt(MediaBrowser.EXTRA_PAGE, -1); int pageSize = options.getInt(MediaBrowser.EXTRA_PAGE_SIZE, -1); if (page == -1 && pageSize == -1) { return list; } int fromIndex = pageSize * page; int toIndex = fromIndex + pageSize; if (page < 0 || pageSize < 1 || fromIndex >= list.size()) { return Collections.EMPTY_LIST; } if (toIndex > list.size()) { toIndex = list.size(); } return list.subList(fromIndex, toIndex); } private void performLoadItem(String itemId, final ConnectionRecord connection, final ResultReceiver receiver) { final Result<MediaBrowser.MediaItem> result = Loading