1 /* 2 * Copyright (C) 2017 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 package com.android.documentsui.inspector; 17 18 import android.content.Context; 19 import android.text.format.Formatter; 20 import android.util.AttributeSet; 21 22 import com.android.documentsui.DocumentsApplication; 23 import com.android.documentsui.R; 24 import com.android.documentsui.base.DocumentInfo; 25 import com.android.documentsui.base.Lookup; 26 import com.android.documentsui.inspector.InspectorController.DetailsDisplay; 27 28 /** 29 * Displays the basic details about a file. 30 */ 31 public class DetailsView extends TableView implements DetailsDisplay { 32 33 public DetailsView(Context context) { 34 this(context, null); 35 } 36 37 public DetailsView(Context context, AttributeSet attrs) { 38 this(context, attrs, 0); 39 } 40 41 public DetailsView(Context context, AttributeSet attrs, int defStyleAttr) { 42 super(context, attrs, defStyleAttr); 43 } 44 45 @Override 46 public void accept(DocumentInfo doc) { 47 48 Lookup<String, String> fileTypeLookup = 49 DocumentsApplication.getFileTypeLookup(getContext()); 50 51 String mimeType = fileTypeLookup.lookup(doc.mimeType); 52 53 put(R.string.sort_dimension_file_type, mimeType); 54 55 // TODO: Each of these rows need to be removed if the condition is false and previously 56 // set. 57 if (doc.size >= 0 && !doc.isDirectory()) { 58 put(R.string.sort_dimension_size, Formatter.formatFileSize(getContext(), doc.size)); 59 } 60 61 if (doc.lastModified > 0) { 62 put(R.string.sort_dimension_date, 63 DateUtils.formatDate(this.getContext(), doc.lastModified)); 64 } 65 66 // We only show summary field when doc is partial (meaning an active download). 67 // The rest of the time "summary" tends to be less than useful. For example 68 // after a download is completed DownloadsProvider include the orig filename 69 // in the summary field. This is confusing to folks in-and-if-itself, but 70 // after the file is renamed, it creates even more confusion (since it still 71 // shows the original). For that reason, and others. We only display on partial files. 72 if (doc.isPartial() && doc.summary != null) { 73 put(R.string.sort_dimension_summary, doc.summary); 74 } 75 } 76 77 @Override 78 public void setChildrenCount(int count) { 79 put(R.string.directory_items, String.valueOf(count)); 80 } 81 } 82