1 /* 2 * Copyright (C) 2016 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.settings.applications; 18 19 import android.app.Fragment; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.UserHandle; 23 import android.provider.DocumentsContract; 24 import android.support.annotation.WorkerThread; 25 import android.text.format.Formatter; 26 import android.util.Log; 27 28 import com.android.settings.R; 29 import com.android.settings.Utils; 30 import com.android.settingslib.applications.StorageStatsSource; 31 32 import java.io.IOException; 33 34 /** 35 * MusicViewHolderController controls an Audio/Music file view in the ManageApplications view. 36 */ 37 public class MusicViewHolderController implements FileViewHolderController { 38 private static final String TAG = "MusicViewHolderController"; 39 40 private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents"; 41 42 private Context mContext; 43 private StorageStatsSource mSource; 44 private String mVolumeUuid; 45 private long mMusicSize; 46 private UserHandle mUser; 47 MusicViewHolderController( Context context, StorageStatsSource source, String volumeUuid, UserHandle user)48 public MusicViewHolderController( 49 Context context, StorageStatsSource source, String volumeUuid, UserHandle user) { 50 mContext = context; 51 mSource = source; 52 mVolumeUuid = volumeUuid; 53 mUser = user; 54 } 55 56 @Override 57 @WorkerThread queryStats()58 public void queryStats() { 59 try { 60 mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes; 61 } catch (IOException e) { 62 mMusicSize = 0; 63 Log.w(TAG, e); 64 } 65 } 66 67 @Override shouldShow()68 public boolean shouldShow() { 69 return true; 70 } 71 72 @Override setupView(AppViewHolder holder)73 public void setupView(AppViewHolder holder) { 74 holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.ic_headset_24dp)); 75 holder.appName.setText(mContext.getText(R.string.audio_files_title)); 76 holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize)); 77 } 78 79 @Override onClick(Fragment fragment)80 public void onClick(Fragment fragment) { 81 Intent intent = new Intent(Intent.ACTION_VIEW); 82 intent.setDataAndType( 83 DocumentsContract.buildRootUri(AUTHORITY_MEDIA, "audio_root"), 84 DocumentsContract.Root.MIME_TYPE_ITEM); 85 intent.addCategory(Intent.CATEGORY_DEFAULT); 86 intent.putExtra(Intent.EXTRA_USER_ID, mUser); 87 Utils.launchIntent(fragment, intent); 88 } 89 } 90