RootInfo.java revision e37ea6123d1aa3cd3e8804988886b1f6046d79d6
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 java.util.Objects; 29 30/** 31 * Representation of a {@link Root}. 32 */ 33public class RootInfo { 34 public String authority; 35 public String rootId; 36 public int rootType; 37 public int flags; 38 public int icon; 39 public String title; 40 public String summary; 41 public String documentId; 42 public long availableBytes; 43 44 public static RootInfo fromRootsCursor(String authority, Cursor cursor) { 45 final RootInfo root = new RootInfo(); 46 root.authority = authority; 47 root.rootId = getCursorString(cursor, Root.COLUMN_ROOT_ID); 48 root.rootType = getCursorInt(cursor, Root.COLUMN_ROOT_TYPE); 49 root.flags = getCursorInt(cursor, Root.COLUMN_FLAGS); 50 root.icon = getCursorInt(cursor, Root.COLUMN_ICON); 51 root.title = getCursorString(cursor, Root.COLUMN_TITLE); 52 root.summary = getCursorString(cursor, Root.COLUMN_SUMMARY); 53 root.documentId = getCursorString(cursor, Root.COLUMN_DOCUMENT_ID); 54 root.availableBytes = getCursorLong(cursor, Root.COLUMN_AVAILABLE_BYTES); 55 56 // TODO: remove this hack 57 if ("com.google.android.apps.docs.storage".equals(root.authority)) { 58 root.flags &= ~(Root.FLAG_PROVIDES_AUDIO | Root.FLAG_PROVIDES_IMAGES 59 | Root.FLAG_PROVIDES_VIDEO); 60 } 61 62 return root; 63 } 64 65 public Drawable loadIcon(Context context) { 66 return DocumentInfo.loadIcon(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