Add a music apps view to the Storage Settings.

When you tap the Music & Audio preference, it takes you a
hybridized applications view. In this view, there also is
a line item which defines the amount of storage used by
audio files on the device. Using the new storage query, we
can add this information very quickly to the view.

Bug: 33199077
Test: Settings robo tests
Change-Id: If51cba0b3de20805543a39049367eb13613081e7
This commit is contained in:
Daniel Nishi
2017-01-19 14:03:57 -08:00
parent a40d72b9e9
commit 31027dae93
11 changed files with 424 additions and 51 deletions

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.settings.applications;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.provider.DocumentsContract;
import android.support.annotation.WorkerThread;
import android.text.format.Formatter;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.deviceinfo.storage.StorageStatsSource;
/**
* MusicViewHolderController controls an Audio/Music file view in the ManageApplications view.
*/
public class MusicViewHolderController implements FileViewHolderController {
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
private Context mContext;
private StorageStatsSource mSource;
private String mVolumeUuid;
private long mMusicSize;
public MusicViewHolderController(
Context context, StorageStatsSource source, String volumeUuid) {
mContext = context;
mSource = source;
mVolumeUuid = volumeUuid;
}
@Override
@WorkerThread
public void queryStats() {
mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, UserHandle.CURRENT).audioBytes;
}
@Override
public boolean shouldShow() {
return true;
}
@Override
public void setupView(AppViewHolder holder) {
holder.appIcon.setImageDrawable(mContext.getDrawable(R.drawable.empty_icon));
holder.appName.setText(mContext.getText(R.string.audio_files_title));
holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
}
@Override
public void onClick(Fragment fragment) {
Intent intent = new Intent(DocumentsContract.ACTION_BROWSE);
intent.setData(DocumentsContract.buildRootUri(AUTHORITY_MEDIA, "audio_root"));
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(Intent.EXTRA_USER_ID, UserHandle.CURRENT);
Utils.launchIntent(fragment, intent);
}
}