The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 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 | |
Marco Nelissen | f33a575 | 2010-01-27 15:35:43 -0800 | [diff] [blame^] | 19 | import com.android.music.MusicUtils.ServiceToken; |
| 20 | |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 21 | import android.app.Activity; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 24 | import android.content.ServiceConnection; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 26 | import android.os.IBinder; |
Marco Nelissen | 3d4b262 | 2010-01-06 12:46:49 -0800 | [diff] [blame] | 27 | import android.os.RemoteException; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 28 | |
| 29 | public class MusicBrowserActivity extends Activity |
Marco Nelissen | ec0c57a | 2009-12-12 12:27:11 -0800 | [diff] [blame] | 30 | implements MusicUtils.Defs { |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 31 | |
Marco Nelissen | f33a575 | 2010-01-27 15:35:43 -0800 | [diff] [blame^] | 32 | private ServiceToken mToken; |
| 33 | |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 34 | public MusicBrowserActivity() { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Called when the activity is first created. |
| 39 | */ |
| 40 | @Override |
| 41 | public void onCreate(Bundle icicle) { |
| 42 | super.onCreate(icicle); |
Marco Nelissen | ec0c57a | 2009-12-12 12:27:11 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 52 | String shuf = getIntent().getStringExtra("autoshuffle"); |
| 53 | if ("true".equals(shuf)) { |
Marco Nelissen | f33a575 | 2010-01-27 15:35:43 -0800 | [diff] [blame^] | 54 | mToken = MusicUtils.bindToService(this, autoshuffle); |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 55 | } |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void onDestroy() { |
Marco Nelissen | f33a575 | 2010-01-27 15:35:43 -0800 | [diff] [blame^] | 60 | if (mToken != null) { |
| 61 | MusicUtils.unbindFromService(mToken); |
| 62 | } |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 63 | super.onDestroy(); |
| 64 | } |
| 65 | |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 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 |
Dave Sparks | 14aeef2 | 2009-03-24 21:23:42 -0700 | [diff] [blame] | 69 | try { |
| 70 | unbindService(this); |
| 71 | } catch (IllegalArgumentException e) { |
| 72 | } |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 73 | IMediaPlaybackService serv = IMediaPlaybackService.Stub.asInterface(obj); |
| 74 | if (serv != null) { |
| 75 | try { |
| 76 | serv.setShuffleMode(MediaPlaybackService.SHUFFLE_AUTO); |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 77 | } catch (RemoteException ex) { |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | public void onServiceDisconnected(ComponentName classname) { |
| 83 | } |
| 84 | }; |
| 85 | |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 86 | } |
| 87 | |