1/* 2 * Copyright (C) 2014 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.session; 18 19import android.media.session.PlaybackState; 20import android.os.Bundle; 21 22import androidx.annotation.RequiresApi; 23 24import java.util.List; 25 26@RequiresApi(21) 27class PlaybackStateCompatApi21 { 28 public static int getState(Object stateObj) { 29 return ((PlaybackState)stateObj).getState(); 30 } 31 32 public static long getPosition(Object stateObj) { 33 return ((PlaybackState)stateObj).getPosition(); 34 } 35 36 public static long getBufferedPosition(Object stateObj) { 37 return ((PlaybackState)stateObj).getBufferedPosition(); 38 } 39 40 public static float getPlaybackSpeed(Object stateObj) { 41 return ((PlaybackState)stateObj).getPlaybackSpeed(); 42 } 43 44 public static long getActions(Object stateObj) { 45 return ((PlaybackState)stateObj).getActions(); 46 } 47 48 public static CharSequence getErrorMessage(Object stateObj) { 49 return ((PlaybackState)stateObj).getErrorMessage(); 50 } 51 52 public static long getLastPositionUpdateTime(Object stateObj) { 53 return ((PlaybackState)stateObj).getLastPositionUpdateTime(); 54 } 55 56 public static List<Object> getCustomActions(Object stateObj) { 57 return (List)((PlaybackState)stateObj).getCustomActions(); 58 } 59 60 public static long getActiveQueueItemId(Object stateObj) { 61 return ((PlaybackState)stateObj).getActiveQueueItemId(); 62 } 63 64 public static Object newInstance(int state, long position, long bufferedPosition, 65 float speed, long actions, CharSequence errorMessage, long updateTime, 66 List<Object> customActions, 67 long activeItemId) { 68 PlaybackState.Builder stateObj = new PlaybackState.Builder(); 69 stateObj.setState(state, position, speed, updateTime); 70 stateObj.setBufferedPosition(bufferedPosition); 71 stateObj.setActions(actions); 72 stateObj.setErrorMessage(errorMessage); 73 for (Object customAction : customActions) { 74 stateObj.addCustomAction((PlaybackState.CustomAction) customAction); 75 } 76 stateObj.setActiveQueueItemId(activeItemId); 77 return stateObj.build(); 78 } 79 80 static final class CustomAction { 81 public static String getAction(Object customActionObj) { 82 return ((PlaybackState.CustomAction)customActionObj).getAction(); 83 } 84 85 public static CharSequence getName(Object customActionObj) { 86 return ((PlaybackState.CustomAction)customActionObj).getName(); 87 } 88 89 public static int getIcon(Object customActionObj) { 90 return ((PlaybackState.CustomAction)customActionObj).getIcon(); 91 } 92 public static Bundle getExtras(Object customActionObj) { 93 return ((PlaybackState.CustomAction)customActionObj).getExtras(); 94 } 95 96 public static Object newInstance(String action, CharSequence name, 97 int icon, Bundle extras) { 98 PlaybackState.CustomAction.Builder customActionObj = 99 new PlaybackState.CustomAction.Builder(action, name, icon); 100 customActionObj.setExtras(extras); 101 return customActionObj.build(); 102 } 103 104 private CustomAction() { 105 } 106 } 107 108 private PlaybackStateCompatApi21() { 109 } 110} 111