• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.Manifest.permission;
20 import android.app.Activity;
21 import android.content.pm.PackageManager;
22 import android.os.Bundle;
23 import com.android.music.utils.LogHelper;
24 
25 public class MusicBrowserActivity extends Activity {
26     private static final String TAG = LogHelper.makeLogTag(MusicBrowserActivity.class);
27 
28     private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 42;
29 
MusicBrowserActivity()30     public MusicBrowserActivity() {}
31 
32     /**
33      * Called when the activity is first created.
34      */
35     @Override
onCreate(Bundle icicle)36     public void onCreate(Bundle icicle) {
37         super.onCreate(icicle);
38         LogHelper.d(TAG, "onCreate()");
39         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 
initApp()48     public void initApp() {
49         int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab);
50         LogHelper.d(TAG, "initApp() activeTab = ", activeTab);
51         if (activeTab != R.id.artisttab && activeTab != R.id.albumtab && activeTab != R.id.songtab
52                 && activeTab != R.id.playlisttab) {
53             activeTab = R.id.artisttab;
54         }
55         MusicUtils.activateTab(this, activeTab);
56     }
57 
58     @Override
onDestroy()59     public void onDestroy() {
60         LogHelper.d(TAG, "onDestroy()");
61         super.onDestroy();
62     }
63 
64     @Override
onRequestPermissionsResult( int requestCode, String permissions[], int[] grantResults)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     }
78 }
79