blob: b6b30e84c713746073afa7fed4339a441e01c0a6 [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
Jack Hef9e434b2017-01-26 16:10:20 -080019import android.Manifest.permission;
The Android Open Source Project792a2202009-03-03 19:32:30 -080020import android.app.Activity;
Jack Hef02d3c62017-02-21 00:39:22 -050021import android.content.pm.PackageManager;
The Android Open Source Project792a2202009-03-03 19:32:30 -080022import android.os.Bundle;
Jack Hef02d3c62017-02-21 00:39:22 -050023import com.android.music.utils.LogHelper;
The Android Open Source Project792a2202009-03-03 19:32:30 -080024
Jack Hef02d3c62017-02-21 00:39:22 -050025public class MusicBrowserActivity extends Activity {
26 private static final String TAG = LogHelper.makeLogTag(MusicBrowserActivity.class);
27
Jack Hef9e434b2017-01-26 16:10:20 -080028 private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 42;
Marco Nelissenf33a5752010-01-27 15:35:43 -080029
Jack Heb0fba8b2017-01-26 15:54:38 -080030 public MusicBrowserActivity() {}
The Android Open Source Project792a2202009-03-03 19:32:30 -080031
32 /**
33 * Called when the activity is first created.
34 */
35 @Override
36 public void onCreate(Bundle icicle) {
37 super.onCreate(icicle);
Jack Hef02d3c62017-02-21 00:39:22 -050038 LogHelper.d(TAG, "onCreate()");
Jack Hef9e434b2017-01-26 16:10:20 -080039 if (checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
40 != PackageManager.PERMISSION_GRANTED) {
41 requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE},
42 MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
43 return;
44 }
45 initApp();
46 }
47
48 public void initApp() {
Marco Nelissenec0c57a2009-12-12 12:27:11 -080049 int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab);
Jack Hef02d3c62017-02-21 00:39:22 -050050 LogHelper.d(TAG, "initApp() activeTab = ", activeTab);
Jack Heb0fba8b2017-01-26 15:54:38 -080051 if (activeTab != R.id.artisttab && activeTab != R.id.albumtab && activeTab != R.id.songtab
Marco Nelissenec0c57a2009-12-12 12:27:11 -080052 && activeTab != R.id.playlisttab) {
53 activeTab = R.id.artisttab;
54 }
55 MusicUtils.activateTab(this, activeTab);
The Android Open Source Project792a2202009-03-03 19:32:30 -080056 }
57
58 @Override
59 public void onDestroy() {
Jack Hef02d3c62017-02-21 00:39:22 -050060 LogHelper.d(TAG, "onDestroy()");
The Android Open Source Project792a2202009-03-03 19:32:30 -080061 super.onDestroy();
62 }
63
Jack Hef9e434b2017-01-26 16:10:20 -080064 @Override
65 public void onRequestPermissionsResult(
66 int requestCode, String permissions[], int[] grantResults) {
67 switch (requestCode) {
68 case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
69 if (grantResults.length == 0
70 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
71 finish();
72 return;
73 }
74 initApp();
75 }
76 }
77 }
The Android Open Source Project792a2202009-03-03 19:32:30 -080078}