MusicBrowserActivity.java revision ec0c57a414c3563ebbf5767d92787a6a3f4a8820
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 android.app.Activity; 20import android.app.SearchManager; 21import android.content.BroadcastReceiver; 22import android.content.ComponentName; 23import android.content.Context; 24import android.content.Intent; 25import android.content.IntentFilter; 26import android.content.ServiceConnection; 27import android.content.SharedPreferences; 28import android.graphics.drawable.Drawable; 29import android.media.AudioManager; 30import android.media.MediaFile; 31import android.net.Uri; 32import android.os.Bundle; 33import android.os.RemoteException; 34import android.os.IBinder; 35import android.provider.MediaStore; 36import android.util.Log; 37import android.view.Menu; 38import android.view.MenuItem; 39import android.view.MotionEvent; 40import android.view.View; 41import android.view.Window; 42import android.widget.ImageButton; 43import android.widget.TextView; 44 45public 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 100