RootInfo.java revision 923396b7720367ec99c889725fddfa556e703971
1/* 2 * Copyright (C) 2013 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.documentsui.model; 18 19import static com.android.documentsui.model.DocumentInfo.getCursorInt; 20import static com.android.documentsui.model.DocumentInfo.getCursorLong; 21import static com.android.documentsui.model.DocumentInfo.getCursorString; 22 23import android.content.Context; 24import android.database.Cursor; 25import android.graphics.drawable.Drawable; 26import android.provider.DocumentsContract.Root; 27 28import com.android.documentsui.IconUtils; 29 30import java.util.Objects; 31 32/** 33 * Representation of a {@link Root}. 34 */ 35public class RootInfo { 36 public String authority; 37 public String rootId; 38 public int rootType; 39 public int flags; 40 public int icon; 41 public String title; 42 public String summary; 43 public String documentId; 44 public long availableBytes; 45 public String[] mimeTypes; 46 47 public static RootInfo fromRootsCursor(String authority, Cursor cursor) { 48 final RootInfo root = new RootInfo(); 49 root.authority = authority; 50 root.rootId = getCursorString(cursor, Root.COLUMN_ROOT_ID); 51 root.rootType = getCursorInt(cursor, Root.COLUMN_ROOT_TYPE); 52 root.flags = getCursorInt(cursor, Root.COLUMN_FLAGS); 53 root.icon = getCursorInt(cursor, Root.COLUMN_ICON); 54 root.title = getCursorString(cursor, Root.COLUMN_TITLE); 55 root.summary = getCursorString(cursor, Root.COLUMN_SUMMARY); 56 root.documentId = getCursorString(cursor, Root.COLUMN_DOCUMENT_ID); 57 root.availableBytes = getCursorLong(cursor, Root.COLUMN_AVAILABLE_BYTES); 58 59 final String raw = getCursorString(cursor, Root.COLUMN_MIME_TYPES); 60 root.mimeTypes = (raw != null) ? raw.split("\n") : null; 61 62 return root; 63 } 64 65 public Drawable loadIcon(Context context) { 66 return IconUtils.loadPackageIcon(context, authority, icon); 67 } 68 69 @Override 70 public boolean equals(Object o) { 71 if (o instanceof RootInfo) { 72 final RootInfo root = (RootInfo) o; 73 return Objects.equals(authority, root.authority) && Objects.equals(rootId, root.rootId); 74 } else { 75 return false; 76 } 77 } 78 79 @Override 80 public int hashCode() { 81 return Objects.hash(authority, rootId); 82 } 83 84 public String getDirectoryString() { 85 return (summary != null) ? summary : title; 86 } 87} 88