1792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project/*
2792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * Copyright (C) 2007 The Android Open Source Project
3792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project *
4792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * you may not use this file except in compliance with the License.
6792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * You may obtain a copy of the License at
7792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project *
8792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project *
10792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * See the License for the specific language governing permissions and
14792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * limitations under the License.
15792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project */
16792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
17792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectpackage com.android.music;
18792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
19f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissenimport com.android.music.MusicUtils.ServiceToken;
20f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissen
21792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.app.Activity;
22792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.content.ComponentName;
23792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.content.Intent;
24792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.content.ServiceConnection;
25792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.os.Bundle;
26792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.os.IBinder;
273d4b2625018856a506a203e046550afd2d9d8a92Marco Nelissenimport android.os.RemoteException;
28792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
29792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectpublic class MusicBrowserActivity extends Activity
30ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen    implements MusicUtils.Defs {
31792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
32f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissen    private ServiceToken mToken;
33f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissen
34792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    public MusicBrowserActivity() {
35792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    }
36792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
37792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    /**
38792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project     * Called when the activity is first created.
39792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project     */
40792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    @Override
41792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    public void onCreate(Bundle icicle) {
42792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        super.onCreate(icicle);
43ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen        int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab);
44ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen        if (activeTab != R.id.artisttab
45ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen                && activeTab != R.id.albumtab
46ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen                && activeTab != R.id.songtab
47ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen                && activeTab != R.id.playlisttab) {
48ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen            activeTab = R.id.artisttab;
49ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen        }
50ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen        MusicUtils.activateTab(this, activeTab);
51ec0c57a414c3563ebbf5767d92787a6a3f4a8820Marco Nelissen
52792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        String shuf = getIntent().getStringExtra("autoshuffle");
53792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        if ("true".equals(shuf)) {
54f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissen            mToken = MusicUtils.bindToService(this, autoshuffle);
55792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        }
56792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    }
57792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
58792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    @Override
59792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    public void onDestroy() {
60f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissen        if (mToken != null) {
61f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissen            MusicUtils.unbindFromService(mToken);
62f33a575c2b09095d58ad7af527113f767e4c37b1Marco Nelissen        }
63792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        super.onDestroy();
64792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    }
65792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
66792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    private ServiceConnection autoshuffle = new ServiceConnection() {
67792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        public void onServiceConnected(ComponentName classname, IBinder obj) {
68792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project            // we need to be able to bind again, so unbind
6914aeef2c63bc9c0be83c906b07bed852144f484aDave Sparks            try {
7014aeef2c63bc9c0be83c906b07bed852144f484aDave Sparks                unbindService(this);
7114aeef2c63bc9c0be83c906b07bed852144f484aDave Sparks            } catch (IllegalArgumentException e) {
7214aeef2c63bc9c0be83c906b07bed852144f484aDave Sparks            }
73792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project            IMediaPlaybackService serv = IMediaPlaybackService.Stub.asInterface(obj);
74792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project            if (serv != null) {
75792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project                try {
76792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project                    serv.setShuffleMode(MediaPlaybackService.SHUFFLE_AUTO);
77792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project                } catch (RemoteException ex) {
78792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project                }
79792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project            }
80792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        }
81792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
82792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        public void onServiceDisconnected(ComponentName classname) {
83792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project        }
84792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project    };
85792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
86792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project}
87792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project
88