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