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