PhotosViewHolderController.java revision a8cac7a409957830c3e05acf346824ca47754a34
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.graphics.drawable.InsetDrawable; 23import android.os.UserHandle; 24import android.support.annotation.WorkerThread; 25import android.text.format.Formatter; 26import android.util.Log; 27 28import com.android.settings.R; 29import com.android.settings.Utils; 30import com.android.settingslib.applications.StorageStatsSource; 31 32import java.io.IOException; 33 34/** PhotosViewHolderController controls an Audio/Music file view in the ManageApplications view. */ 35public class PhotosViewHolderController implements FileViewHolderController { 36 private static final String TAG = "PhotosViewHolderCtrl"; 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 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 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 69 public boolean shouldShow() { 70 return true; 71 } 72 73 @Override 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 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