1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.v4.media; 18 19import android.media.browse.MediaBrowser; 20import android.os.Bundle; 21import android.support.annotation.NonNull; 22import android.support.annotation.RequiresApi; 23 24import java.util.List; 25 26@RequiresApi(24) 27class MediaBrowserCompatApi24 { 28 public static Object createSubscriptionCallback(SubscriptionCallback callback) { 29 return new SubscriptionCallbackProxy<>(callback); 30 } 31 32 public static void subscribe(Object browserObj, String parentId, Bundle options, 33 Object subscriptionCallbackObj) { 34 ((MediaBrowser) browserObj).subscribe(parentId, options, 35 (MediaBrowser.SubscriptionCallback) subscriptionCallbackObj); 36 } 37 38 public static void unsubscribe(Object browserObj, String parentId, 39 Object subscriptionCallbackObj) { 40 ((MediaBrowser) browserObj).unsubscribe(parentId, 41 (MediaBrowser.SubscriptionCallback) subscriptionCallbackObj); 42 } 43 44 interface SubscriptionCallback extends MediaBrowserCompatApi21.SubscriptionCallback { 45 void onChildrenLoaded(@NonNull String parentId, List<?> children, @NonNull Bundle options); 46 void onError(@NonNull String parentId, @NonNull Bundle options); 47 } 48 49 static class SubscriptionCallbackProxy<T extends SubscriptionCallback> 50 extends MediaBrowserCompatApi21.SubscriptionCallbackProxy<T> { 51 public SubscriptionCallbackProxy(T callback) { 52 super(callback); 53 } 54 55 @Override 56 public void onChildrenLoaded(@NonNull String parentId, 57 List<MediaBrowser.MediaItem> children, @NonNull Bundle options) { 58 mSubscriptionCallback.onChildrenLoaded(parentId, children, options); 59 } 60 61 @Override 62 public void onError(@NonNull String parentId, @NonNull Bundle options) { 63 mSubscriptionCallback.onError(parentId, options); 64 } 65 } 66} 67