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 | |
Jack He | f9e434b | 2017-01-26 16:10:20 -0800 | [diff] [blame] | 19 | import android.Manifest.permission; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 20 | import android.app.Activity; |
Jack He | f02d3c6 | 2017-02-21 00:39:22 -0500 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 22 | import android.os.Bundle; |
Jack He | f02d3c6 | 2017-02-21 00:39:22 -0500 | [diff] [blame] | 23 | import com.android.music.utils.LogHelper; |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 24 | |
Jack He | f02d3c6 | 2017-02-21 00:39:22 -0500 | [diff] [blame] | 25 | public class MusicBrowserActivity extends Activity { |
| 26 | private static final String TAG = LogHelper.makeLogTag(MusicBrowserActivity.class); |
| 27 | |
Jack He | f9e434b | 2017-01-26 16:10:20 -0800 | [diff] [blame] | 28 | private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 42; |
Marco Nelissen | f33a575 | 2010-01-27 15:35:43 -0800 | [diff] [blame] | 29 | |
Jack He | b0fba8b | 2017-01-26 15:54:38 -0800 | [diff] [blame] | 30 | public MusicBrowserActivity() {} |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Called when the activity is first created. |
| 34 | */ |
| 35 | @Override |
| 36 | public void onCreate(Bundle icicle) { |
| 37 | super.onCreate(icicle); |
Jack He | f02d3c6 | 2017-02-21 00:39:22 -0500 | [diff] [blame] | 38 | LogHelper.d(TAG, "onCreate()"); |
Jack He | f9e434b | 2017-01-26 16:10:20 -0800 | [diff] [blame] | 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 | |
| 48 | public void initApp() { |
Marco Nelissen | ec0c57a | 2009-12-12 12:27:11 -0800 | [diff] [blame] | 49 | int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab); |
Jack He | f02d3c6 | 2017-02-21 00:39:22 -0500 | [diff] [blame] | 50 | LogHelper.d(TAG, "initApp() activeTab = ", activeTab); |
Jack He | b0fba8b | 2017-01-26 15:54:38 -0800 | [diff] [blame] | 51 | if (activeTab != R.id.artisttab && activeTab != R.id.albumtab && activeTab != R.id.songtab |
Marco Nelissen | ec0c57a | 2009-12-12 12:27:11 -0800 | [diff] [blame] | 52 | && activeTab != R.id.playlisttab) { |
| 53 | activeTab = R.id.artisttab; |
| 54 | } |
| 55 | MusicUtils.activateTab(this, activeTab); |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void onDestroy() { |
Jack He | f02d3c6 | 2017-02-21 00:39:22 -0500 | [diff] [blame] | 60 | LogHelper.d(TAG, "onDestroy()"); |
The Android Open Source Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 61 | super.onDestroy(); |
| 62 | } |
| 63 | |
Jack He | f9e434b | 2017-01-26 16:10:20 -0800 | [diff] [blame] | 64 | @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 Project | 792a220 | 2009-03-03 19:32:30 -0800 | [diff] [blame] | 78 | } |