OSDN Git Service

d82cdff52f5e9fbefe0a62381cb806117f50f834
[android-x86/packages-apps-Music.git] / src / com / android / music / MusicBrowserActivity.java
1 /*
2  * Copyright (C) 2007 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 com.android.music;
18
19 import android.app.Activity;
20 import android.content.ComponentName;
21 import android.content.Intent;
22 import android.content.ServiceConnection;
23 import android.os.Bundle;
24 import android.os.IBinder;
25 import android.os.RemoteException;
26
27 public class MusicBrowserActivity extends Activity
28     implements MusicUtils.Defs {
29
30     public MusicBrowserActivity() {
31     }
32
33     /**
34      * Called when the activity is first created.
35      */
36     @Override
37     public void onCreate(Bundle icicle) {
38         super.onCreate(icicle);
39         int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab);
40         if (activeTab != R.id.artisttab
41                 && activeTab != R.id.albumtab
42                 && activeTab != R.id.songtab
43                 && activeTab != R.id.playlisttab) {
44             activeTab = R.id.artisttab;
45         }
46         MusicUtils.activateTab(this, activeTab);
47         
48         String shuf = getIntent().getStringExtra("autoshuffle");
49         if ("true".equals(shuf)) {
50             bindService((new Intent()).setClass(this, MediaPlaybackService.class), autoshuffle, 0);
51         }
52     }
53
54     @Override
55     public void onDestroy() {
56         MusicUtils.unbindFromService(this);
57         super.onDestroy();
58     }
59
60     private ServiceConnection autoshuffle = new ServiceConnection() {
61         public void onServiceConnected(ComponentName classname, IBinder obj) {
62             // we need to be able to bind again, so unbind
63             try {
64                 unbindService(this);
65             } catch (IllegalArgumentException e) {
66             }
67             IMediaPlaybackService serv = IMediaPlaybackService.Stub.asInterface(obj);
68             if (serv != null) {
69                 try {
70                     serv.setShuffleMode(MediaPlaybackService.SHUFFLE_AUTO);
71                 } catch (RemoteException ex) {
72                 }
73             }
74         }
75
76         public void onServiceDisconnected(ComponentName classname) {
77         }
78     };
79
80 }
81