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.graphics.drawable.InsetDrawable; 23 import android.os.UserHandle; 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 /** PhotosViewHolderController controls an Audio/Music file view in the ManageApplications view. */ 35 public class PhotosViewHolderController implements FileViewHolderController { 36 private static final String TAG = "PhotosViewHolderController"; 37 38 private static final String IMAGE_MIME_TYPE = "image/*"; 39 private static final int INSET_SIZE = 24; // dp 40 41 private Context mContext; 42 private StorageStatsSource mSource; 43 private String mVolumeUuid; 44 private long mFilesSize; 45 private UserHandle mUser; 46 PhotosViewHolderController( Context context, StorageStatsSource source, String volumeUuid, UserHandle user)47 public PhotosViewHolderController( 48 Context context, StorageStatsSource source, String volumeUuid, UserHandle user) { 49 mContext = context; 50 mSource = source; 51 mVolumeUuid = volumeUuid; 52 mUser = user; 53 } 54 55 @Override 56 @WorkerThread queryStats()57 public void queryStats() { 58 try { 59 StorageStatsSource.ExternalStorageStats stats = 60 mSource.getExternalStorageStats(mVolumeUuid, mUser); 61 mFilesSize = stats.imageBytes + stats.videoBytes; 62 } catch (IOException e) { 63 mFilesSize = 0; 64 Log.w(TAG, e); 65 } 66 } 67 68 @Override shouldShow()69 public boolean shouldShow() { 70 return true; 71 } 72 73 @Override setupView(AppViewHolder holder)74 public void setupView(AppViewHolder holder) { 75 holder.appIcon.setImageDrawable( 76 new InsetDrawable(mContext.getDrawable(R.drawable.ic_photo_library), INSET_SIZE)); 77 holder.appName.setText(mContext.getText(R.string.storage_detail_images)); 78 holder.summary.setText(Formatter.formatFileSize(mContext, mFilesSize)); 79 } 80 81 @Override onClick(Fragment fragment)82 public void onClick(Fragment fragment) { 83 Intent intent = new Intent(); 84 intent.setAction(android.content.Intent.ACTION_VIEW); 85 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); 86 intent.setType(IMAGE_MIME_TYPE); 87 intent.putExtra(Intent.EXTRA_FROM_STORAGE, true); 88 Utils.launchIntent(fragment, intent); 89 } 90 } 91