OSDN Git Service

Music player UI refresh.
[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.app.SearchManager;
21 import android.content.BroadcastReceiver;
22 import android.content.ComponentName;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.IntentFilter;
26 import android.content.ServiceConnection;
27 import android.content.SharedPreferences;
28 import android.graphics.drawable.Drawable;
29 import android.media.AudioManager;
30 import android.media.MediaFile;
31 import android.net.Uri;
32 import android.os.Bundle;
33 import android.os.RemoteException;
34 import android.os.IBinder;
35 import android.provider.MediaStore;
36 import android.util.Log;
37 import android.view.Menu;
38 import android.view.MenuItem;
39 import android.view.MotionEvent;
40 import android.view.View;
41 import android.view.Window;
42 import android.widget.ImageButton;
43 import android.widget.TextView;
44
45 public class MusicBrowserActivity extends Activity
46     implements MusicUtils.Defs {
47
48     public MusicBrowserActivity() {
49     }
50
51     /**
52      * Called when the activity is first created.
53      */
54     @Override
55     public void onCreate(Bundle icicle) {
56         super.onCreate(icicle);
57         int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab);
58         if (activeTab != R.id.artisttab
59                 && activeTab != R.id.albumtab
60                 && activeTab != R.id.songtab
61                 && activeTab != R.id.playlisttab) {
62             activeTab = R.id.artisttab;
63         }
64         MusicUtils.activateTab(this, activeTab);
65         
66         String shuf = getIntent().getStringExtra("autoshuffle");
67         if ("true".equals(shuf)) {
68             bindService((new Intent()).setClass(this, MediaPlaybackService.class), autoshuffle, 0);
69         }
70     }
71
72     @Override
73     public void onDestroy() {
74         MusicUtils.unbindFromService(this);
75         super.onDestroy();
76     }
77
78     private ServiceConnection autoshuffle = new ServiceConnection() {
79         public void onServiceConnected(ComponentName classname, IBinder obj) {
80             // we need to be able to bind again, so unbind
81             try {
82                 unbindService(this);
83             } catch (IllegalArgumentException e) {
84             }
85             IMediaPlaybackService serv = IMediaPlaybackService.Stub.asInterface(obj);
86             if (serv != null) {
87                 try {
88                     serv.setShuffleMode(MediaPlaybackService.SHUFFLE_AUTO);
89                 } catch (RemoteException ex) {
90                 }
91             }
92         }
93
94         public void onServiceDisconnected(ComponentName classname) {
95         }
96     };
97
98 }
99