blob: 1c4a9d1ac386f72e2700cf9d252fe912f4028a87 [file] [log] [blame]
The Android Open Source Project792a2202009-03-03 19:32:30 -08001/*
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
Marco Nelissenf33a5752010-01-27 15:35:43 -080019import com.android.music.MusicUtils.ServiceToken;
20
The Android Open Source Project792a2202009-03-03 19:32:30 -080021import android.app.Activity;
The Android Open Source Project792a2202009-03-03 19:32:30 -080022import android.content.ComponentName;
The Android Open Source Project792a2202009-03-03 19:32:30 -080023import android.content.Intent;
The Android Open Source Project792a2202009-03-03 19:32:30 -080024import android.content.ServiceConnection;
The Android Open Source Project792a2202009-03-03 19:32:30 -080025import android.os.Bundle;
The Android Open Source Project792a2202009-03-03 19:32:30 -080026import android.os.IBinder;
Marco Nelissen3d4b2622010-01-06 12:46:49 -080027import android.os.RemoteException;
The Android Open Source Project792a2202009-03-03 19:32:30 -080028
29public class MusicBrowserActivity extends Activity
Marco Nelissenec0c57a2009-12-12 12:27:11 -080030 implements MusicUtils.Defs {
The Android Open Source Project792a2202009-03-03 19:32:30 -080031
Marco Nelissenf33a5752010-01-27 15:35:43 -080032 private ServiceToken mToken;
33
The Android Open Source Project792a2202009-03-03 19:32:30 -080034 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 Nelissenec0c57a2009-12-12 12:27:11 -080043 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 Project792a2202009-03-03 19:32:30 -080052 String shuf = getIntent().getStringExtra("autoshuffle");
53 if ("true".equals(shuf)) {
Marco Nelissenf33a5752010-01-27 15:35:43 -080054 mToken = MusicUtils.bindToService(this, autoshuffle);
The Android Open Source Project792a2202009-03-03 19:32:30 -080055 }
The Android Open Source Project792a2202009-03-03 19:32:30 -080056 }
57
58 @Override
59 public void onDestroy() {
Marco Nelissenf33a5752010-01-27 15:35:43 -080060 if (mToken != null) {
61 MusicUtils.unbindFromService(mToken);
62 }
The Android Open Source Project792a2202009-03-03 19:32:30 -080063 super.onDestroy();
64 }
65
The Android Open Source Project792a2202009-03-03 19:32:30 -080066 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 Sparks14aeef22009-03-24 21:23:42 -070069 try {
70 unbindService(this);
71 } catch (IllegalArgumentException e) {
72 }
The Android Open Source Project792a2202009-03-03 19:32:30 -080073 IMediaPlaybackService serv = IMediaPlaybackService.Stub.asInterface(obj);
74 if (serv != null) {
75 try {
76 serv.setShuffleMode(MediaPlaybackService.SHUFFLE_AUTO);
The Android Open Source Project792a2202009-03-03 19:32:30 -080077 } catch (RemoteException ex) {
78 }
79 }
80 }
81
82 public void onServiceDisconnected(ComponentName classname) {
83 }
84 };
85
The Android Open Source Project792a2202009-03-03 19:32:30 -080086}
87