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;
21import android.os.SystemClock;
22
23import java.util.ArrayList;
24import java.util.List;
25
26class PlaybackStateCompatApi21 {
27    public static int getState(Object stateObj) {
28        return ((PlaybackState)stateObj).getState();
29    }
30
31    public static long getPosition(Object stateObj) {
32        return ((PlaybackState)stateObj).getPosition();
33    }
34
35    public static long getBufferedPosition(Object stateObj) {
36        return ((PlaybackState)stateObj).getBufferedPosition();
37    }
38
39    public static float getPlaybackSpeed(Object stateObj) {
40        return ((PlaybackState)stateObj).getPlaybackSpeed();
41    }
42
43    public static long getActions(Object stateObj) {
44        return ((PlaybackState)stateObj).getActions();
45    }
46
47    public static CharSequence getErrorMessage(Object stateObj) {
48        return ((PlaybackState)stateObj).getErrorMessage();
49    }
50
51    public static long getLastPositionUpdateTime(Object stateObj) {
52        return ((PlaybackState)stateObj).getLastPositionUpdateTime();
53    }
54
55    public static List<Object> getCustomActions(Object stateObj) {
56        return (List)((PlaybackState)stateObj).getCustomActions();
57    }
58
59    public static long getActiveQueueItemId(Object stateObj) {
60        return ((PlaybackState)stateObj).getActiveQueueItemId();
61    }
62
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 {
80        public static String getAction(Object customActionObj) {
81            return ((PlaybackState.CustomAction)customActionObj).getAction();
82        }
83
84        public static CharSequence getName(Object customActionObj) {
85            return ((PlaybackState.CustomAction)customActionObj).getName();
86        }
87
88        public static int getIcon(Object customActionObj) {
89            return ((PlaybackState.CustomAction)customActionObj).getIcon();
90        }
91        public static Bundle getExtras(Object customActionObj) {
92            return ((PlaybackState.CustomAction)customActionObj).getExtras();
93        }
94
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