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