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 17package com.android.settings.applications.manageapplications; 18 19import android.app.Fragment; 20import android.content.Context; 21import android.content.Intent; 22import android.os.UserHandle; 23import android.support.annotation.WorkerThread; 24import android.text.format.Formatter; 25import android.util.Log; 26 27import com.android.settings.R; 28import com.android.settings.Utils; 29import com.android.settingslib.applications.StorageStatsSource; 30 31import java.io.IOException; 32 33/** PhotosViewHolderController controls an Audio/Music file view in the ManageApplications view. */ 34public class PhotosViewHolderController implements FileViewHolderController { 35 private static final String TAG = "PhotosViewHolderCtrl"; 36 37 private static final String IMAGE_MIME_TYPE = "image/*"; 38 39 private Context mContext; 40 private StorageStatsSource mSource; 41 private String mVolumeUuid; 42 private long mFilesSize; 43 private UserHandle mUser; 44 45 public PhotosViewHolderController( 46 Context context, StorageStatsSource source, String volumeUuid, UserHandle user) { 47 mContext = context; 48 mSource = source; 49 mVolumeUuid = volumeUuid; 50 mUser = user; 51 } 52 53 @Override 54 @WorkerThread 55 public void queryStats() { 56 try { 57 StorageStatsSource.ExternalStorageStats stats = 58 mSource.getExternalStorageStats(mVolumeUuid, mUser); 59 mFilesSize = stats.imageBytes + stats.videoBytes; 60 } catch (IOException e) { 61 mFilesSize = 0; 62 Log.w(TAG, e); 63 } 64 } 65 66 @Override 67 public boolean shouldShow() { 68 return true; 69 } 70 71 @Override 72 public void setupView(ApplicationViewHolder holder) { 73 holder.setIcon(R.drawable.ic_photo_library); 74 holder.setTitle(mContext.getText(R.string.storage_detail_images)); 75 holder.setSummary(Formatter.formatFileSize(mContext, mFilesSize)); 76 } 77 78 @Override 79 public void onClick(Fragment fragment) { 80 Intent intent = new Intent(); 81 intent.setAction(android.content.Intent.ACTION_VIEW); 82 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); 83 intent.setType(IMAGE_MIME_TYPE); 84 intent.putExtra(Intent.EXTRA_FROM_STORAGE, true); 85 Utils.launchIntent(fragment, intent); 86 } 87} 88